再会,
我有一个带有 RadTextbox 的 GridTemplateColumn。文本框值由 javascript 更改。但是当我单击文本框时,它会变回原来的值。
请帮忙
javascript
<title>Untitled Page</title>
<script type="text/javascript">
function changeCountry() {
var grid = $find('<%=RadGrid1.ClientID %>');
var MasterTable = grid.get_masterTableView();
var dataItems = MasterTable.get_dataItems();
var cellCountry = dataItems[0].get_cell("CountryCol");
var txtCountry = $telerik.$(cellCountry).find('input')[0];
txtCountry.value = "New Country";
}
</script>
.aspx
<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" CellSpacing="0" GridLines="None" PageSize="20" AutoGenerateColumns="false" OnItemDataBound="RadGrid1_ItemDataBound">
<FilterMenu EnableImageSprites="False">
</FilterMenu>
<ClientSettings>
<Selecting CellSelectionMode="None" AllowRowSelect="True" />
</ClientSettings>
<MasterTableView>
<CommandItemSettings ExportToPdfText="Export to PDF" />
<RowIndicatorColumn FilterControlAltText="Filter RowIndicator column" Visible="True">
</RowIndicatorColumn>
<ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column" Visible="True">
</ExpandCollapseColumn>
<Columns>
<telerik:GridBoundColumn DataField="CR_Branch" HeaderText="Branch"></telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="CR_Country" HeaderText="Branch" Display=false></telerik:GridBoundColumn>
<telerik:GridTemplateColumn HeaderText="CR_Country" DataField="CR_Country" UniqueName="CountryCol">
<ItemTemplate>
<telerik:RadTextBox ID="txtCountry" runat="server"></telerik:RadTextBox>
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
<EditFormSettings>
<EditColumn FilterControlAltText="Filter EditCommandColumn column">
</EditColumn>
</EditFormSettings>
</MasterTableView>
</telerik:RadGrid>
.aspx.cs
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridHeaderItem)
{
}
if (e.Item is GridDataItem)
{
GridDataItem dataItem = (GridDataItem)e.Item;
RadTextBox txtCountry = ((RadTextBox)dataItem.FindControl("txtCountry"));
txtCountry.Text = dataItem["CR_Country"].Text;
}
}