将 radgrid 绑定到树状数据结构
我有一个如下所示的结构,
Class TreeNode {
public TreeNode Parent { get; }
public IEnumerable<TreeNode> Children { get; }
public . . . .
}
我想将其绑定到 asp.net telerik radgrid,其中包含每个级别的子级的详细信息表。我知道 radgrid 支持使用数据源控件声明性绑定到自引用层次结构,但假设您有一个平面数据集(例如来自数据库)并且可以查看某种父键字段。我的问题是有人将 radgrid 绑定到这样的数据结构吗?有没有办法以声明方式或主要以声明方式执行此操作?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我无法直接回答你的问题,因为我没有使用 Telerik 网格的经验,但我可以提供解决方法。
向您的类添加一个方法,将其内容扁平化为自引用表之类的结构,例如您提到的结构。这样,您仍然可以像您希望的那样使用该类及其更高级的结构,但仍然可以以符合 UI 组件期望的可使用形式输出内容。
这也是扩展方法的一个很好的候选者。
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.
我能想到的另一种可能的方法是通过根据 DetailTableDataBind 网格处理程序内的父表过滤子表的日期来动态构建层次结构。这个演示是一个很好的参考:
http://demos .telerik.com/aspnet-ajax/grid/examples/programming/detailtabledatabind/defaultcs.aspx
但我必须同意斯蒂芬的建议可能更方便。
迪克
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