In essence, site map data is layered, which means that each node can contain zero or multiple subnodes. The Treeview and menu controls are used to process hierarchical data. However, you can also bind site map data to non-hierarchical controls, such as dropdownlist, checkboxlist, and other controls that display data in linear or flat format.
Note: Only the sitemappath control and the control that supports the inavigateuidata interface render the site map node as a link.
Example
The following code example uses the dropdownlist control to display site map data from the Web. sitemap file.
When the client selects an item from the drop-down list, the browser will be redirected to the selected page. This is achieved by calling the Redirect method in the onselectedindexchanged event handler.
If you place this sample code on the master page, the startfromcurrentnode attribute in the sitemapdatasource control ensures that a site map is always displayed in the drop-down list, starting from the page currently being executed.
<% @ Page Language = "C #" autoeventwireup = "true" %>
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<SCRIPT runat = "server">
Void _ onselectedindexchanged (Object sender, eventargs E)
{
Response. Redirect (dropdownlist1.selecteditem. value );
}
</SCRIPT>
<HTML>
<Head runat = "server">
<Title> dropdownlist bound to sitemapdatasource </title>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div>
<Asp: sitemapdatasource id = "sitemapdatasource1" runat = "server"
Startfromcurrentnode = "true"
Showstartingnode = "false"/>
<Asp: dropdownlist id = "dropdownlist1" runat = "server"
Performanceid = "sitemapdatasource1"
Autopostback = "true"
Datatextfield = "title"
Datavaluefield = "url"
Onselectedindexchanged = "_ onselectedindexchanged">
</ASP: dropdownlist>
</Div>
</Form>
</Body>
</Html>
If the page does not contain any child nodes, the drop-down list will be empty. If the client selects an item but does not set the corresponding URL attribute in the web. sitemap file, the client will be redirected to the home page of the application.