我从未在 asp.net 中使用过 treeview 控件,但现在我需要将数据绑定(bind)到它。我来自 sql server 的存储过程返回如下值。我正在使用 C#
TermID ParentID Name
2021 0 A. Geographic locations
3602 2021 Oceania
3604 3602 Australasia
3621 3604 New Zealand
3619 3604 Pacific Islands
3585 3619 Polynesia
3592 3585 Samoa
3594 3592 American Samoa
每个Term都有parentID,任何一个ParentID=0的TermID都是根节点。我们如何将这些数据绑定(bind)到 treeview。我将不胜感激任何建议或示例
最佳答案
这可能有用:
TreeView 控件需要像 xml/sitemaps 这样的分层数据结构,所以我们不能直接将 DataTable 绑定(bind)到它。使用数据表 Select where ParentID = ID
请使用递归方法创建与当前菜单项 ID 相关的子项,请引用下面的链接获取代码。
http://www.charith.gunasekara.web-sphere.co.uk/2010/10/how-to-bind-datatable-to-aspnet.html
n 下面的链接将帮助您创建自己的 TreeView 控件。
关于c# - 如何在 asp.net c# treeview 控件中绑定(bind)数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14803189/