How to: Display Site-Map Data in Non-Hierarchical Web Server Controls
Site-map data is inherently hierarchical, which means that each node can contain zero or more child nodes. Theand controls are designed to work with hierarchical data. However, you can bind site-map data to non-hierarchical controls, such as the , , and other controls that display data in a linear, or flat, format.
Only thecontrol and controls that support the interface render site-map nodes as links.
The following code example uses a DropDownList control to display the site-map data from a Web.sitemap file.
When a client selects an item in the drop-down list, the browser is redirected to the selected page. This is accomplished by calling themethod in the OnSelectedIndexChanged event handler.
If this code example is placed in a master page, then theproperty in the control will ensure that the drop-down list always displays a site map that begins at the currently executing page.
If the page does not contain any child nodes, then the drop-down list will be empty. If the client selects an item for which there is no URL property set in the Web.sitemap file, then the client is redirected to the home page of the application.
Compiling the Code
This example requires a valid Web.sitemap file that references the ASP.NET Web page that contains the code example. If you put this example code in a file that is not listed in one of the nodes in the Web.sitemap file, remove the following property from the control: