You want to use a dynamic menu in your application and display a breadcrumb trail to show the current location within the application and to provide an easy way for the user to navigate back to a previous location.
Implement the dynamic menu solution described in Recipe 21.8 and add a SiteMapPath control to the .master file. Use the .master file as the master page for all pages in your application that require the dynamic menu and the breadcrumb trail.
Example 21-24 shows the .master file used to display the dynamic menu and breadcrumb trail. Figure 21-9 shows the output a sample page with the breadcrumb trail displayed.
Figure 21-9. Sample page with dynamic menu and breadcrumb trail
To improve the user experience, applications commonly display a breadcrumb trail to show the current location within the application and to provide an easy way to navigate back to a previous location. The site navigation infrastructure provided in ASP.NET 2.0 can be used to display a breadcrumb trail using the data in the Web.sitemap file that is also used to as the data source for dynamic menus (see Recipe 21.8).
Once you have the site structure defined in the Web.sitemap file, as described in Recipe 21.8, all that is required is to add a SiteMapPath control to the .master file that will be used as the master page for your application pages that need to display a breadcrumb trail.
The SiteMapPath control uses the site map provider defined by the SiteMapProvider attribute. If the SiteMapProvider attribute is not defined, the SiteMapPath control will use the default SiteMapProvider, which by default is the XmlSiteMapProvider.
The SiteMapPath control displays a series of nodes that match the hierarchy defined in the Web.sitemap file from the root SiteMapNode to the SiteMapNode used to define the currently displayed page. All nodes from the root node to the current page node will be displayed in the breadcrumb trail. By default, all nodes except the current node will be defined as hyperlinks to provide the ability to navigate back up the hierarchy.
If you want the current node displayed as a hyperlink, you can set the RenderCurrentNodeAsLink attribute to true.
The SiteMapPath control provides many attributes that can be used to define the look and feel of the rendered breadcrumb trail. In addition, it provides the ability to define templates to be used for the root node (RootNodeTemplate), the current node (CurrentNodeTemplate), the nodes in between the root and current node (NodeTemplate), and the separator used between the nodes (PathSeparatorTemplate). The combination of the templates and attributes provides nearly unlimited ways to display your breadcrumb trail.
The XmlSiteMapProvider along with the SiteMapDataSource, Menu, and SiteMapPath controls will meet the menu system needs of most applications. Other controls can be used if they do not meet the needs of your application, such as using the treeView control instead of the Menu control. In addition, all of the controls can be manipulated programmatically if you need to adjust their output more.
Recipe 21.8; the Menu, SiteMapPath, and treeView controls in the MSDN Library
Example 21-24. Master page with dynamic menu and breadcrumb trail (.master)