i

ASP.Net A Complete Guide

SiteMapDataSource

The control is a data source for the site map data. That data is stored by the site map providers & that is configured for our site. The SiteMapDataSource allows Web server controls such as the TreeView, Menu, and DropDownList controls, to bind to hierarchical site map data (that are not specifically site navigation controls). Wecan use these Web server controls to show a site map as a table of contents. We can use SiteMapPath control, which is created specifically as a site navigation control.

Specifying the Starting Node:

It binds to the site map data and represents the view based on a specified starting node in the site map hierarchy. The first node is identified by the values of several SiteMapDataSource properties as follows:

Starting Node

Property

The root node in the hierarchy (the default setting).

The StartFromCurrentNode = false.

The StartingNodeUrl if not set.

The node represents the currently viewed page.

StartFromCurrentNode = true.

The StartingNodeUrl is not set.

 

A specific node of the hierarchy.

The StartFromCurrentNode = false.

The StartingNodeUrl is set.

Let’s see one example of “SiteMapDataSource” control:

Create a web site and add the file “SiteMapDataSourceFile." After that, add the SiteMapDataSource by dragging and dropping on the web page, as shown in the i mage below.

Right-click on theproject in Solution Explorer and click Add New Item. On templates, select the Site Map template and click OK, as shown below.

 

Choose a DataSource for TreeView control. I will display the site map in a TreeView. As you can see below, I select SiteMapDataSource as my Data Source for the TreeView control.

In the image below, We can see the code of "Web.sitemap."

Now build & run the application, and we can see the output. Here, we can see the contents of the SiteMap file are displayed in a TreeView format and under a root node with multiple children.