This tutorial will demonstrate how to use the treeview control to create hierarchical links for a web site using ASP.NET 4.0 and C#.
Configuring the TreeView
To demonstrate using the tree view, we will need to create a simple web page. At this point, I have created a new ASP.NET Empty Web Site. To begin:
Now that we have our page setup, we need to add a tree view to it. But first, what exactly is a tree view anwyays? A tree view is a simple view that contains a series of nodes or links that can be nested into one another. The reason it is called a tree view is because nested nodes branch off into multiple different nodes. This allows the tree view to contain tons of different links while still being highly organized. To add the tree view:
Now that we have a tree view, we can start adding in some nodes. To do this, add in the following code to the tree view <Nodes> tag:
This will add in three different links at the top level, home, page4, and page5. Furthermore, this will branch the home link off into 3 more links in the bottom level, page1, page2, and page3. The resulting tree view should look like this:

I just signed up at Server Intellect and couldn't be more pleased with my fully scalable & redundant cloud hosting! Check it out and see for yourself.
Testing
To test this out you need to load up the web site and ensure that all of the links are functional. Furthermore, you can test expanding and contracting the home node that contains child nodes. This functionality of the tree view is what allows it to keep large amounts of links organized.
To demonstrate using the tree view, we will need to create a simple web page. At this point, I have created a new ASP.NET Empty Web Site. To begin:
- Right click the project in your solution explorer.
- Select add new item...
- Select a web form.
- Name it 'Default.aspx'.
- Click add.
Now that we have our page setup, we need to add a tree view to it. But first, what exactly is a tree view anwyays? A tree view is a simple view that contains a series of nodes or links that can be nested into one another. The reason it is called a tree view is because nested nodes branch off into multiple different nodes. This allows the tree view to contain tons of different links while still being highly organized. To add the tree view:
- Open Default.aspx to design mode.
- Expand the navigation tab of your toolbox.
- Drag and drop a treeview onto the web form.
Now that we have a tree view, we can start adding in some nodes. To do this, add in the following code to the tree view <Nodes> tag:
<asp:TreeNode Value="Home" NavigateUrl="~/Default.aspx" Text="Home"> |
This will add in three different links at the top level, home, page4, and page5. Furthermore, this will branch the home link off into 3 more links in the bottom level, page1, page2, and page3. The resulting tree view should look like this:

I just signed up at Server Intellect and couldn't be more pleased with my fully scalable & redundant cloud hosting! Check it out and see for yourself.
Testing
To test this out you need to load up the web site and ensure that all of the links are functional. Furthermore, you can test expanding and contracting the home node that contains child nodes. This functionality of the tree view is what allows it to keep large amounts of links organized.
No comments:
Post a Comment