c# - 如何在 asp.net c# treeview 控件中绑定(bind)数据

标签 c# asp.net treeview

我从未在 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 控件。

http://www.codeproject.com/KB/tree/DataBoundTreeView.aspx

关于c# - 如何在 asp.net c# treeview 控件中绑定(bind)数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14803189/

相关文章:

c# - 如何将字节转换为字符串?

c# - 在 Windows 10 通用应用程序中播放音频和视频?

c# - 为什么 `[DllImport]` 会以 `RtlSecureZeroMemory` 的入口点失败,即使它是一个有据可查的入口点?

asp.net - 使用 mvccontrib 创建带有第一个选项文本的选择列表?

python - 如何让 tkinter treeview 适合你的框架

java - 无法单击 TreeView 中的元素 - Selenium webdriver java

c# - 使用 IComparer 进行排序

javascript - 单击按钮时获取显示在文本框中的日期

c# - 如何在源代码中隐藏 .asmx web 服务 API 端点?

ios - 生成新的 UITableViewController 并显示它