【发布时间】:2012-09-25 13:37:31
【问题描述】:
我正在使用我的一个表单中的 RadGrid 用 C# 开发一个网站。下面是我的 RadGrid 的 ASPX 代码:
<telerik:RadGrid ID="GridViewAllocation" runat="server" Height="200px" Width="100%"
AutoGenerateColumns="False" GridLines="None"
OnItemDataBound="GridViewAllocation_ItemDataBound"
OnItemCommand="GridViewAllocation_ItemCommand">
<MasterTableView>
<Columns>
<telerik:GridBoundColumn HeaderText="Amount O/S" UniqueName="AMT" DataField="AMT">
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn HeaderText="Allocate" UniqueName="Acc_Allocated"
DataField="Acc_Allocated">
<ItemTemplate>
<telerik:RadNumericTextBox ID="TextGirdAmntAlloc" runat="server" Value="0"
CssClass="gridTextEntry" OnTextChanged="TextGirdAmntAlloc_TextChanged"
AutoPostBack="true">
<NumberFormat GroupSeparator="" DecimalDigits="4" />
</telerik:RadNumericTextBox>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn UniqueName="ACC_SOURCE" DataField="ACC_SOURCE" Visible="false">
</telerik:GridBoundColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
在此网格中,当我单击或 KeyPress 或任何其他事件时,我想将列 AMT 的确切值传输到文本框 Acc_Allocated。传递值有一个条件: 当 Acc_Source 值为 "3" 时转移该值,否则不转移。目前我正在通过 TextChanged 事件从服务器端进行检查。
还有其他方法吗?
这是我的 TextChanged 事件:
protected void TextGirdAmntAlloc_TextChanged(object sender, EventArgs e)
{
try
{
foreach (GridDataItem GrdItm in GridViewAllocation.MasterTableView.Items)
{
decimal GrdAccAllocAmnt = Convert.ToDecimal(((RadNumericTextBox)GrdItm.FindContro("TextGirdAmntAlloc")).Text);
if (GrdItm["ACC_SOURCE"].Text == "3")
{
LblAmnt_Alloc.Text = GrdItm.Cells[4].Text;
((RadNumericTextBox)GrdItm.FindControl("TextGirdAmntAlloc")).Text = GrdItm.Cells[4].Text;
}
}
}
catch { }
}
【问题讨论】: