0

当我单击 Telerik RadGrid 上的一行时,我可以触发以下方法。我可以引用任何列,例如 item["Description"]

问题:如何引用'Id'的DataKeyName

<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" AllowSorting="True"
            AutoGenerateColumns="False" DataSourceID="LinqDataSource1" GridLines="None" OnItemDataBound="materialsGrid_ItemDataBound" OnItemCommand="RadGrid1_ItemCommand">
            <ClientSettings EnableRowHoverStyle="true" AllowKeyboardNavigation="true" EnablePostBackOnRowClick="true">
            <Selecting AllowRowSelect="True" />
        </ClientSettings>

            <MasterTableView DataKeyNames="Id" DataSourceID="LinqDataSource1" CssClass="listItems"
                Width="98%">


protected void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
    {
        GridDataItem item = (GridDataItem)e.Item; 
        string str = item["Description"].Text;
        var Id = item["Id"];
4

3 回答 3

0
<telerik:GridBoundColumn DataField="Id" HeaderText="Id" SortExpression="Id" Visible="false"
 UniqueName="Id">
 </telerik:GridBoundColumn>


protected void dave_ItemCommand(object source, GridCommandEventArgs e)
{
        GridDataItem item = (GridDataItem)e.Item;
        Guid Id = new Guid(item["Id"].Text);

我作弊并使用了隐藏列。必须有一个更好的方法,但是这让它工作!

于 2010-08-10T03:03:07.663 回答
0

In two years of using RadGrid I've always used a hidden column, a pain but that's the way they [Telerik] have told me to use it.

于 2010-08-10T09:01:03.693 回答
0

我看到您将 ID 字段添加到主表的 DataKeyNames - 为什么不使用 DataKeyValues 从网格行中获取 id 值?请参阅这篇文章以获得先机。

迪克

于 2010-08-24T16:14:44.373 回答