2010-08-10 62 views
0

当我单击Telerik RadGrid上的一行时,我可以触发以下方法。我可以引用任何列例如项目的[“描述”]Telerik Grid - 引用选定的项目

问题:如何以引用的DataKeyName“ID”

<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"]; 

回答

0

在使用RadGrid的两年中,我总是使用隐藏列,但是这是他们[Telerik]告诉我使用它的方式。

+0

不会item.OwnerTableView.DataKeyValues [“Id”]工作吗? – Galilyou 2011-09-27 17:13:47

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); 

我欺骗和使用的隐藏列。必须有更好的方法,但是这会让它工作起来!

0

我看到您将ID字段添加到主表的DataKeyNames中 - 为什么不使用DataKeyValues从网格行中获取id值?请参阅this article以取得成功。

迪克