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

Accessing parent key on NeedDatasource

2 Answers 122 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Lajos
Top achievements
Rank 1
Lajos asked on 08 Nov 2011, 08:49 AM
Hello, Telerik Team,

I have a question about hierarchical RadGrids. I have a hierarchical RadGrid, called RadGrid1. Inside RadGrid1.MasterTableView.NestedViewTemplate I have another grid, RadGrid2. Both of the RadGrids are created from code behind. I've defined this relation:

RadGrid1.MasterTableView.NestedViewSettings.ParentTableRelation.Add(New Telerik.Web.UI.GridRelationFields() With {.DetailKeyField = "ID", .MasterKeyField = "ID"})

My question is: How can I get the ID of the parent table in RadGrid2.NeedDatasource event?

Thank you in advance,
Lajos Arpad.

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 08 Nov 2011, 09:09 AM
Hello Lajos,

Try the following code snippet.
C#:
protected void RadGrid2_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
  RadGrid innergrid=(RadGrid)sender;
  GridNestedViewItem nesteditem = (GridNestedViewItem)innergrid.NamingContainer;
  string dataKeyValue = Convert.ToString(((GridDataItem)(nesteditem.ParentItem)).GetDataKeyValue("ID"));
}

Thanks,
Princy.
0
Lajos
Top achievements
Rank 1
answered on 08 Nov 2011, 09:51 AM
Hello, Princy, thank you for your answer, it worked like a charm.
Tags
Grid
Asked by
Lajos
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Lajos
Top achievements
Rank 1
Share this question
or