This is a migrated thread and some comments may be shown as answers.

Hierarchical Grid - get key of selected detail row and its parent

1 Answer 252 Views
Grid
This is a migrated thread and some comments may be shown as answers.
David Hodges
Top achievements
Rank 1
David Hodges asked on 23 Feb 2009, 04:46 PM
I have a hierarchical grid with one detail table within each row of a Master Table.
I have GridbuttonColumns on the master table rows and detail table rows for selecting rows, and an event hooked to OnItemCommand.
In Code behind (C#) for the ItemCommand post back, how do I get the key of the detail row they selected, plus the key of that row's parent in the master table?

Thanks!

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 24 Feb 2009, 06:36 AM
Hello David,

I hope you are trying to access the DataKeyValues fro the detailrow and the master row on clicking the button in the detail row of your hierarchial grid. If so, you can try out the following code:
aspx:
<telerik:RadGrid OnItemCommand="RadGrid1_ItemCommand" DataSourceID="SqlDataSource1" ID="RadGrid1" runat="server">  
       <MasterTableView DataKeyNames="ProductName" Name="Master">  
       <DetailTables>  
        <telerik:GridTableView DataKeyNames="OrderID"  DataSourceID="SqlDataSource2" Name="Detail" runat="server" >            
        <Columns>    
        <telerik:GridButtonColumn Text="Select" CommandName="Select" UniqueName="ClickButton">  
        </telerik:GridButtonColumn>  
           .... 

cs:
  protected void RadGrid2_ItemCommand(object source, GridCommandEventArgs e)  
    {  
       if (e.CommandName == "Select")  
         {  
            if (e.Item.OwnerTableView.Name == "Detail")  
              {  
                 GridDataItem item = (GridDataItem)e.Item;  
                 string rowKeyValue = item.GetDataKeyValue("OrderID").ToString();  
                 string parentRowKeyValue = item.OwnerTableView.ParentItem.GetDataKeyValue("ProductName").ToString();  
              }  
         }  
     }  

Thanks
Princy.
Tags
Grid
Asked by
David Hodges
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or