views:

36

answers:

3

Hi

When I click a row on my Telerik RadGrid, I can fire the following method. I can reference any of the columns eg item["Description"]

Problem: How to reference the DataKeyName of '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"];
A: 
<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);

I cheated and used a hidden column. There has to be a better way, however this gets it working!

Dave
A: 

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.

Phil Bennett
A: 

I see that you added the ID field to the DataKeyNames of the master table - why not using DataKeyValues to get the id values from the grid rows? See this article for a headstart.

Dick

Dick Lampard