如何在asp.net中生成TreeView? [英] How the generate TreeView in asp.net?

查看:93
本文介绍了如何在asp.net中生成TreeView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑下表。它有3个提交以下数据。现在我想在asp.net中的TreeView控件中显示数据和c#

我将选择DataTable中的所有数据。



category_id category_name parents_id

1 Root NULL

2老师1

3学生1

4老师A 2

5老师B 2

6老师C 2

7学生A 3

8学生B 3

9学生C 3



提前感谢

Rashed

解决方案

这里有两个可能有用的链接:

从SQL自联接表填充ASP .Net Treeview [ ^ ]

从表格到树视图...显示层次结构 [ ^ ]


 TreeView控件可以在任何情况下使用您需要在其中显示分层数据。例如,您可以使用此控件提供站点导航,以父/子关系显示数据库表中的数据库记录,显示XML文档的内容,或显示文件系统中的文件和文件夹。您还可以以编程方式访问TreeView对象模型,以动态创建树,填充节点,设置属性等。 TreeView控件由节点组成,您可以将三种类型的节点添加到TreeView控件中。 

Root - 根节点是没有父节点的节点。它有一个或多个子节点。
Parent - 具有父节点和一个或多个子节点的节点
Leaf - 没有子节点的节点

使用TreeView控件的最简单方法是指定一组静态树节点。以下是如何定义TreeView节点声明的示例:

< asp: TreeView ID = TreeView1 runat = server >

< 节点 >

< asp:TreeNode 文字 = 产品 Val ue = 产品 >

< asp:TreeNode 文本 = 计算机 = 计算机 >

< asp:TreeNode Text = 品牌 = B rand > < / asp :TreeNode >

< asp:TreeNode 文本 = Compatable Value = 可比较的 > < / asp:TreeNode >

< / asp:TreeNode >

< asp:TreeNode 文本 = NoteBooks Value = 笔记本 > < / asp:TreeNode >

< asp:TreeNode 文本 = HardDisks = < span class =code-keyword> HardDisks > < / asp:TreeNode >

< asp:TreeNode 文本 = 监控 = 监控 > < / asp:TreeNode >

< < span class =code-leadattribute> / asp:TreeNode >

< / Nodes >

< / asp:TreeView >

此外,您可以使用TreeView提供站点导航功能,在这种情况下,您需要配置TreeView以使用SiteMapDataSource动态显示SiteMap节点。

TreeView和菜单控件可以为网站导航提供一个很好的解决方案,特别是如果它们与角色和安全修整功能相结合。



< br $> b $ b

http://www.aspxcode.net/free-asp-net-navigation-source-code.aspx?Topics=How%20to%20Use%20TreeView [ ^ ]





ASP带模板的.NET AJAX TreeView控件 [ ^


Consider the following table. It has 3 filed with the following data. Now I want to show the data in TreeView Control in asp.net and c#
I will select all the data in a DataTable.

category_id category_name parents_id
1 Root NULL
2 Teacher 1
3 Student 1
4 TeacherA 2
5 TeacherB 2
6 TeacherC 2
7 StudentA 3
8 StudentB 3
9 StudentC 3

thanks in advance
Rashed

解决方案

Here are two links that may help:
Populate an ASP .Net Treeview from a SQL self-join table [^]
From Table to TreeView…Displaying Hierarchies[^]


The TreeView control can be used  in any situation in which you need to display hierarchical data. For example, you can use this control to provide a site navigation, displaying database records from database tables in a Parent/Child relation, displaying the contents of an XML document, or displaying files and folders from the file system. It is also possible for you to programmatically access the TreeView object model to dynamically create trees, populate nodes, set properties and so on. The TreeView control consists of nodes and there are three types of nodes that you can add to a TreeView control.

    Root - A root node is a node that has no parent node. It has one or more child nodes.
    Parent - A node that has a parent node and one or more child nodes
    Leaf - A node that has no child nodes

The easiest way to use the TreeView control is to specify a static set of tree nodes . the following is an example on how to define the TreeView Nodes Declarativley :

<asp:TreeView ID="TreeView1" runat="server">

    <Nodes>

       <asp:TreeNode Text="Products" Value="Products">

         <asp:TreeNode Text="Computers" Value="Computers">

             <asp:TreeNode Text="Brand" Value="Brand"></asp:TreeNode>

             <asp:TreeNode Text="Compatable" Value="Compatable"></asp:TreeNode>

          </asp:TreeNode>

          <asp:TreeNode Text="NoteBooks" Value="NoteBooks"></asp:TreeNode>

          <asp:TreeNode Text="HardDisks" Value="HardDisks"></asp:TreeNode>

          <asp:TreeNode Text="Monitors" Value="Monitors"></asp:TreeNode>

      </asp:TreeNode>

   </Nodes>

</asp:TreeView>

Also you can use the TreeView to provider a Site Navigation capabilities, in this case you need to configure the TreeView  to use the SiteMapDataSource To Dynamicly display the SiteMap Nodes .

The TreeView and Menu Controls can provide a good solution for site Navigation ,specially if they combined with the Roles and Security Trimming Capabilities.




http://www.aspxcode.net/free-asp-net-navigation-source-code.aspx?Topics=How%20to%20Use%20TreeView[^]


An ASP.NET AJAX TreeView control with templates[^]


这篇关于如何在asp.net中生成TreeView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆