views:

309

answers:

2

I have a structure that looks following

Class TreeNode  {
    public TreeNode Parent { get; }
    public IEnumerable<TreeNode> Children { get; }
    public . . . . 
}

I want to bind this to a asp.net telerik radgrid with detail tables for each level of the children. I know that radgrid supports declarative binding to a self referencing hierarchy using a datasource control but that assumes you have a flat dataset (e.g. from a database) and can look at a parent key field of some sort. My question has anyone bound a radgrid to a data structure like this before and is there a way to do it declaratively or mostly declaratively?

A: 

I can't answer your question directly since I've no experience with the telerik grid, but I can offer a work around.

Add a method to your class that flattens its contents into a self-referencing table like structure such as the one you mentioned. This way you can still work with the class and it's more advanced structure like you want to, but can still output the contents in a consumable form that matches the expectations of the UI components.

This is also a good candidate for an extension method too.

Stephen M. Redd
Thank you for the suggestion. That's what I have done in the meantime just curious to see if there was another way.
Dustin Hodges
A: 

Another possible way I can think of is to build the hierarchy dynamically by filtering the date for the child tables based on their parent inside the DetailTableDataBind grid handler. This demo is a good reference:

http://demos.telerik.com/aspnet-ajax/grid/examples/programming/detailtabledatabind/defaultcs.aspx

but I must agree that Stephen's suggestion might be more handy.

Dick

Dick Lampard