[英]Telerik Grid - Referencing a Selected Item
当我在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"];
<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);
我作弊并使用了隐藏栏。 必须有一种更好的方法,但这可以使它起作用!
在使用RadGrid的两年中,我总是使用隐藏的列,这很痛苦,但这就是他们[Telerik]告诉我使用它的方式。
我看到您将ID字段添加到了主表的DataKeyNames中-为什么不使用DataKeyValues从网格行中获取ID值? 请参阅本文以了解更多信息。
迪克
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.