Static Breadcrumb with SiteMapPath Control
Today I saw a question in the ASP.NET newsgroup asking about
implementing a static (non-hyperlinked) site map path. As you know, the
SiteMapPath
control in ASP.NET 2.0 displays a breadcrumb showing the current spot in the
site map navigation defined in the
web.sitemap XML file. Parent nodes in
the current navigation path are shown as links to the respective pages, each
separated by the path separation character (defined by the
SiteMapPath.PathSeparator
property). However, if you would like a static breadcrumb, that is, without
making parent nodes as links but as plain text, just hook into the
ItemDataBound event of the
SiteMapPath control and clear the navigation URL (originally taken from the
web.sitemap file) for every node.
Assuming a simple SiteMapPath markup as below:
<asp:SiteMapPath ID="SiteMapPath1" runat="server" CurrentNodeStyle-Font-Bold="true" NodeStyle-Font-Size="Small" OnItemDataBound="SiteMapPath1_ItemDataBound" PathDirection="RootToCurrent" PathSeparator=" > " PathSeparatorStyle-Font-Size="Small" RenderCurrentNodeAsLink="false">
Have the following for the ItemDataBound event:
protected void SiteMapPath1_ItemDataBound (object sender, SiteMapNodeItemEventArgs e)
{
{
if (e.Item.ItemType == SiteMapNodeItemType.Parent || e.Item.ItemType == SiteMapNodeItemType.Root)
{
// Control index may vary if additional controls have been defined in the node template
((HyperLink)e.Item.Controls[0]).NavigateUrl = "";
}
}
}
The result would look something like this (assuming an apporpriate web.sitemap file is in place):

Without this change, the same SiteMapPath control would look like (parent pages hyperlinked):
