开发者

Binding a radgrid to a tree like data structure

开发者 https://www.devze.com 2022-12-13 12:41 出处:网络
I have a structure that looks following Class TreeNode{ public TreeNode Parent { get; } public IEnumerable<TreeNode> Children { get; }

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?


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消