Home » ASP.NET Basics » 05 - Site Navigation
5

Adding TreeView Control

Explains what treeview controls are and how to create them

The `TreeView' control is another site navigation control provided by ASP.NET 2.0. The process of adding a TreeView control is almost similar to that of the Menu control. First, we need to create the Web.sitemap file. Then, a SiteMapDataSource control should be added to our master page. Since we already have these two in our project, we will use them in this example.

  • Delete the Menu control from the master page by clicking on the control and pressing the delete key from the keyboard. Make sure that the SiteMapDataSource control is not deleted.
  • Look for the TreeView control in the `Navigation' section of the ToolBox. Drag and drop the control to just below the SiteMapDataSource control.

As soon as we drop the control on the page, the smart tag opens up. From the `Choose Data Source' drop-down list, select `SiteMapDataSource1' option.

That is it! The TreeView control now displays the pages of our site.

Just like the Menu control, we can format the display of the TreeView control. Click on the smart tag arrow of the control and select Auto Format option. A dialog box shows different available styles. Select the required style and click on the OK button.

Save the project and run it. The browser displays our site with the TreeView navigation control.