如何递归填充 ASP.NET Treeview?

发布于 2024-10-27 00:32:28 字数 1678 浏览 0 评论 0原文

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

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();
    }

}

}

如何使用递归将parent 分配给nodeParent,将source 分配给nodeSource,将catName 分配给nodeName?

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

I have an ASP.NET treeview control that needs to be populated recursively from a series of objects. At the minimum, I need to hierarchically display the category name and description for each source and parent node. To this end, I've written the following in my codebehind page:

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();
    }

}

}

How do I use recursion to assign parent to nodeParent, source to nodeSource and catName to nodeName?

Thanks much for your help and guidance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

懵少女 2024-11-03 00:32:28

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

一个很好的示例是在这里找到在这里您可以看到如何以递归方式创建IHierarchyData

The easiest (and most readable) way is to create a class that implements the IHierarchyData interface. This exposes a node of a hierarchical data structure, including the node object and some properties that describe characteristics of the node. Objects that implement the IHierarchyData interface can be contained in IHierarchicalEnumerable collections, and are used by ASP.NET site navigation (like sitemaps) and data source controls.

a great sample of that is found here and here you see how to create IHierarchyData in a recursive manner

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文