0

我有一个带有 delete_command 事件的 radgrid

protected void PointsAccountDefinitionGrid_DeleteCommand(object sender, GridCommandEventArgs e)
{
    GridDataItem item = (GridDataItem)e.Item;
    string giftID = item["giftId"].Text;
}

但是giftID返回“”(空字符串)

有什么帮助吗??

4

1 回答 1

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
}
于 2013-09-10T12:35:35.447 回答