两个数据表到嵌套列表<myclass>

时间:2016-05-25 12:42:49

标签: asp.net-mvc list recursion datatable treeview

我有两个DataTable的数据:

dtTree = "SELECT UnqID, category FROM ExpressionCategorys" 

dtTreeInner = "SELECT Name FROM Expressions WHERE FK_Category = '{" & dtTree.Rows(i)("UnqID").ToString & "}'  

我的问题是,我可以在下面给出这么长的编码方式,但是如何将数据从DataTable传递到List(因为dtTree是父节点, dtTreeInner是子节点??

-Expressions          (topnode static)
--Standard            (childnode of Expressions - this data comes from  dtTree) 
--- ApplicationRef    (childnode - this data comes from  dtTreeInner ) 
--- ApplicationStat   (childnode - this data comes from  dtTreeInner ) 
--- Longdate          (childnode - this data comes from  dtTreeInner ) 
--- ShortDate         (childnode - this data comes from  dtTreeInner ) 
--Address             (childnode of Expressions  - this data comes from  dtTree) 

treeview

如何使用for循环自动完成此过程?

注意:我正在尝试在ASP.NET MVC中创建TreeView

public class Node
{
    public int NodeID { get; set; }
    public string NodeName { get; set; }
    public string NodeText { get; set; }
    public eNodeType NodeType { get; set; }
    public List <Node> Childern { get; set; }
    public string NodeParent { get; set; }
    public string FirstParent { get; set; }
}

List<Node> nodes = new List<Node>();
    nodes.Add(
                new Node() //Expressions
                {
                    NodeID = 0, NodeName = "nExp", NodeType = eNodeType.Exp, NodeText = "Expressions", 
                    Childern = new List<Node>()
                    {
                       new Node () //Standard
                       {
                           NodeID = 1,NodeName = "Standard",NodeType = eNodeType.Exp,NodeText = "Standard",NodeParent ="Expressions",FirstParent="Expressions",
                            Childern = new List<Node>()
                            {
                                 new Node () {NodeID = 2, NodeName = "[*Application Reference]",NodeType = eNodeType.Data,NodeText = "[*Application Reference]",NodeParent ="Standard",FirstParent="Expressions" },
                                 new Node () {NodeID = 3, NodeName = "[*Application status]",NodeType = eNodeType.Data,NodeText = "[*Application status]",NodeParent ="Standard",FirstParent="Expressions"},
                                 new Node () {NodeID = 4, NodeName = "[*Long Date]",NodeType = eNodeType.Data,NodeText = "[*Long Date]",NodeParent ="Standard",FirstParent="Expressions"},
                                 new Node () {NodeID = 5, NodeName = "[*Short Date]",NodeType = eNodeType.Data,NodeText = "[*Short Date]",NodeParent ="Standard",FirstParent="Expressions"}

                            }
                       }
}

0 个答案:

没有答案