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

Hierarchichal Grid using custom objects

1 Answer 20 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mike Hale
Top achievements
Rank 1
Mike Hale asked on 20 Aug 2010, 07:56 PM
I have a class that has a property which is a collection of other objects (think Order with List<OrderDetail>). I want to populate the nested grid with the child objects (Order Detail) but I can't get to the parent object in the DetailTableBind event, and I can't find how to specify the property that contains the child data. The documentation is clear for requerying the database everytime to get the nested data, but that isn't always practical in the real world.

1 Answer, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 25 Aug 2010, 04:04 PM
Hi Mike,

You can get the DataKeyValue for the parent item and use it to fetch the correct data item from the data source like that:
object dataKeyValue = ((source as RadGrid).NamingContainer as DataItem).GetDataKeyValue("ID"); 
//use the dataKeyValue to fetch the correct Employee object
The above code assumes you have an Employee property named ID and you use it as the data key value for the RadGrid data item (by settings DataKeyNames="ID" in the respective GridTableView).

Also, you should wire the nested RadGrid's NeedDataSource event and bind the control there.

Additionally, you can view this forum thread, as a few possible issues connected to your scenario were discussed there.

Regards,
Tsvetina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Mike Hale
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Share this question
or