Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

TreeView

0.00/5 (No votes)
13 Oct 2013 1  
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: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 :

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here