选择表单模型以创建树层次结构 [英] Select form modle to create the tree hierarchy

查看:71
本文介绍了选择表单模型以创建树层次结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I have data retrieved form database in model in list. data is
ParetnID   |     ChildID
101               100
102               101
103               100
104               102
105               100
106               101
107               102
108               104
109               100
110               101

Now I need to create the tree hierarchy of this data.
I am unable to select the parent and child tree hierarchy.
In view I need to display as;
100
|--->101
      |->102
          |->104
              |->108
          |->107
      |->106
      |->110
|--->103
|--->105
|--->109

推荐答案

这很容易。太糟糕了,你没有标记你想要使用的UI库和应用程序类型,但这将涵盖大多数可能的情况:

http://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.aspx [ ^ ],

http://msdn.microsoft.com/en-us/ library / system.windows.controls.treeview.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.treeview.aspx [ ^ ]。



祝你好运,

-SA
This is quite easy. Too bad you did not tag what UI library and application type do you want to use, but this will cover most possible cases:
http://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.controls.treeview.aspx[^],
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.treeview.aspx[^].

Good luck,
—SA


我在MVC Ext.Net 2.1中这样做

我需要的是在树形层次结构中显示上述数据在视图中订购。

我用linq选择了ParentID及其子项等等。



这里是下面的代码

尝试

I am doing this in MVC Ext.Net 2.1
What I need is to show the above data in tree hierarchy order in the view.
I have used the linq to select the ParentID and its children and so on.

here is the code below
try
public virtual List<mymodel> mymodelhierarchy(IEnumerable<mymodel> mydata)   
{
                var families = mydata.ToLookup(x => x.ParnetID);
                var topmost = families.First().Select(s => s);
                Func<string,>> children = null;
                children = (parentId) => families[parentId]
                    .OrderBy(x => x.ChildID)
                    .Select(x => new mymodel(x, children(x.ParentID), mydata)).OrderBy(o => o.ChildID).ToList();
                var value= topmost.Select(mod => new mymodel(mod, children(mod.ChildID), mydata)).ToList();

                return value;
            }</mymodel></mymodel>







上面的代码返回列表中的第一行子节点而不是其他节点。




the above code is returning the first row of the list children and not others.


有数据库错误....

上面提到的代码有效......
There was the database error....
The code mentioned above works....


这篇关于选择表单模型以创建树层次结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆