如何递归填充 ASP.NET Treeview?
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最简单(也是最易读)的方法是创建一个实现 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 inIHierarchicalEnumerable
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