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

Hierarchical Grid Parent field value

3 Answers 207 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dharmesh Barochia
Top achievements
Rank 1
Dharmesh Barochia asked on 13 Nov 2009, 09:30 AM
Hi,

I have master/detail record in hierarchical grid. When the user expands a row in the parent table the details record loaded.  Now inside detail record when user press Add/Edit button it call Grid’s ItemCommand event, here I need to obtain the value of parent row that is not in column but those fields are binded with grid.

I know that we can find parent record’s key value using following code, but I want to find other column then key value.

 

GridDataItem parentItem = e.OwnerTableView.ParentItem;

Int32 IDValue;

Int32.TryParse(Convert.ToString(parentItem.GetDataKeyValue("Key")), out IDValue);

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 13 Nov 2009, 10:18 AM
Hello Dharmesh,

You can try out the following code to access the parent row's cell value on clicking edit button in the child table:
c#:
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
    { 
        if((e.CommandName==RadGrid.EditCommandName||e.CommandName==RadGrid.InitInsertCommandName) && e.Item.OwnerTableView.Name == "Detail"
        {             
            GridDataItem parentItem = (GridDataItem)e.Item.OwnerTableView.ParentItem; 
            string strtxt = parentItem["ColumnUniqueName"].Text; 
        } 
    } 

Thanks
Princy.
0
Dharmesh Barochia
Top achievements
Rank 1
answered on 16 Nov 2009, 06:04 AM

Thanks,

Using this method I can find parent record’s values which are on the grid.  Can I find those values which are not on the screen?

0
Princy
Top achievements
Rank 2
answered on 16 Nov 2009, 09:37 AM
Hello Dharmesh,

You can set the invisible columns as the KeyValue fields of the grid and then retrieve the values in the code behind. For instance, check out the sample code:
aspx:
<telerik:RadGrid ID="RadGrid1" DataSourceID="SqlDataSource1" AutoGenerateColumns="false" runat="server"  OnItemCommand="RadGrid1_ItemCommand"
      <MasterTableView CommandItemDisplay="Top" Name="Master" DataKeyNames="LastName,Notes,Date" DataSourceID="SqlDataSource1"
             <DetailTables> 
                    <telerik:GridTableView DataSourceID="SqlDataSource2" Name="Detail" CommandItemDisplay="Top" AutoGenerateColumns="false">                     
                   

c#:
 protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
    { 
        if ((e.CommandName==RadGrid.EditCommandName||e.CommandName==RadGrid.InitInsertCommandName) && e.Item.OwnerTableView.Name == "Detail"
        {             
            GridDataItem parentItem = (GridDataItem)e.Item.OwnerTableView.ParentItem; 
            string strtxt1 = parentItem.GetDataKeyValue("LastName").ToString(); 
            string strtxt2 = parentItem.GetDataKeyValue("Notes").ToString(); 
            string strtxt3 = parentItem.GetDataKeyValue("Date").ToString(); 
        } 
    } 

Hope this helps..
Princy.
Tags
Grid
Asked by
Dharmesh Barochia
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Dharmesh Barochia
Top achievements
Rank 1
Share this question
or