Click here to Skip to main content
15,886,689 members
Articles / Web Development / ASP.NET

TreeView

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
13 Oct 2013CPOL1 min read 16.4K   3  
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

This articles was originally at wiki.asp.net but has now been given a new home on CodeProject. Editing rights for this article has been set at Bronze or above, so please go in and edit and update this article to keep it fresh and relevant.

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
<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.

More Resources On TreeView :

This article was originally posted at http://wiki.asp.net/page.aspx/373/treeview

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
The ASP.NET Wiki was started by Scott Hanselman in February of 2008. The idea is that folks spend a lot of time trolling the blogs, googlinglive-searching for answers to common "How To" questions. There's piles of fantastic community-created and MSFT-created content out there, but if it's not found by a search engine and the right combination of keywords, it's often lost.

The ASP.NET Wiki articles moved to CodeProject in October 2013 and will live on, loved, protected and updated by the community.
This is a Collaborative Group

754 members

Comments and Discussions

 
-- There are no messages in this forum --