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. The TreeView and Menu controls are designed to work with hierarchical data. However, you can bind site-map data to non-hierarchical controls, such as the DropDownList, CheckBoxList, and other controls that display data in a linear, or flat, format.


Only the SiteMapPath control and controls that support the INavigateUIData 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 the Redirect method in the OnSelectedIndexChanged event handler.

If this code example is placed in a master page, then the StartFromCurrentNode property in the SiteMapDataSource control will ensure that the drop-down list always displays a site map that begins at the currently executing page.

<%@ Page Language="VB"  AutoEventWireup="True" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<script runat="server">
  Public Sub _OnSelectedIndexChanged(ByVal Sender As Object, ByVal e As EventArgs)
  End Sub

<html xmlns="" >
<head runat="server">
    <title>Untitled Page</title>
    <form id="form1" runat="server">
      <asp:SiteMapDataSource ID="SiteMapDataSource1" Runat="Server"
          ShowStartingNode="false" />
      <asp:DropDownList ID="DropDownList1" Runat="Server" 
          OnSelectedIndexChanged="_OnSelectedIndexChanged" >

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.

  • 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:


Community Additions