我有一个带有delete_command事件的radgrid
protected void PointsAccountDefinitionGrid_DeleteCommand(object sender, GridCommandEventArgs e)
{
GridDataItem item = (GridDataItem)e.Item;
string giftID = item["giftId"].Text;
}
但giftID返回“”(空字符串)
任何帮助??
答案 0 :(得分:0)
请尝试使用以下代码段。
ASPX
<MasterTableView DataKeyNames="ID">
<Columns>
<telerik:GridBoundColumn DataField="Name" UniqueName="MyName" HeaderText="Name">
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn>
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("Name") %>'></asp:TextBox>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridEditCommandColumn>
</telerik:GridEditCommandColumn>
</Columns>
</MasterTableView>
ASPX.CS
protected void RadGrid1_DeleteCommand(object sender, GridCommandEventArgs e)
{
GridDataItem item = e.Item as GridDataItem;
string strID = item.GetDataKeyValue("ID").ToString(); //Using DataKey
string strName1 = item["MyName"].Text; // Using BoundColumn UniqueName
string strName2 = (item.FindControl("TextBox1") as TextBox).Text; // Using TemplateColumn Control
}