C# 如何递归地填充ASP.NET树视图?

C# 如何递归地填充ASP.NET树视图?,c#,asp.net,recursion,treeview,C#,Asp.net,Recursion,Treeview,我有一个ASP.NET treeview控件,需要从一系列对象递归填充该控件。至少,我需要分层显示每个源节点和父节点的类别名称和描述。为此,我在我的代码隐藏页面中写了以下内容: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using CATALooK.Automat

我有一个ASP.NET treeview控件,需要从一系列对象递归填充该控件。至少,我需要分层显示每个源节点和父节点的类别名称和描述。为此,我在我的代码隐藏页面中写了以下内容:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CATALooK.Automation;

namespace VBayUnMatched  
{
public partial class VBayCats : System.Web.UI.UserControl
{
    private int id;
    private CATALooK.Automation.SourceInfo source;
    private CATALooK.Automation.CategoryInfo parent;
    private string catID;
    private string catName;
    private string desc;
    private string rawData;
    private int advCatID;
    private DateTime lastUpdated;
    protected void Page_Load(object sender, EventArgs e)
    {
        CategoryController cc = new CategoryController();
        CategoryInfo ci = new CategoryInfo
        (id,source,parent,catID,catName,desc,rawData,advCatID,lastUpdated);
        //CATALooK.AdvCatInfoRemote[] acir = cc.getAdvancedCategories();
        TreeView trvUnMatchedCats = new TreeView();
        TreeNodeCollection tnColl = new TreeNodeCollection();
        TreeNode nodeSource = new TreeNode { Value = ToString(source) };
        TreeNode nodeParent = new TreeNode { Value = ToString(parent) };
        TreeNode nodeName = new TreeNode { Value = catName };
    }

    private void PopulateTreeview()
    {


    }

    private string ToString(SourceInfo source)
    {
        throw new NotImplementedException();
    }

    private string ToString(CategoryInfo parent)
    {
        throw new NotImplementedException();
    }

}
}

如何使用递归将父节点分配给nodeParent,将源节点分配给nodeSource,将catName分配给nodeName

非常感谢您的帮助和指导。

最简单(也是最可读)的方法是创建一个实现
IHierarchyData
接口的类。这将公开分层数据结构的节点,包括节点对象和描述节点特征的一些属性。实现IHierarchyData接口的对象可以包含在
IHierarchicalEnumerable
集合中,并由ASP.NET站点导航(如站点地图)和数据源控件使用

一个很好的例子是如何以递归方式创建
IHierarchyData