I need to hide current node in custom bread crumb on master page. I'm using SiteMapPath control which is already customized. I'm taking custom sitemap from web.sitemap file and all is configured in web.config properly.
How to do it?
I need to hide current node in custom bread crumb on master page. I'm using SiteMapPath control which is already customized. I'm taking custom sitemap from web.sitemap file and all is configured in web.config properly.
How to do it?
Additional problem occurs when I discovered that when I hide last child, separator will stay visible.
I've found some solution:
I will use OnItemDataBound
definition: <asp:SiteMapPath OnItemDataBound="SiteMapNodeItemEventHandler" /
>
implementation: <asp:SiteMapPath ID="siteMapPath" runat="server" SiteMapProvider="CustomSiteMapProvider" OnItemDataBound="SiteMapPath_OnItemDataBound"
>
cs part:
protected void SiteMapPath_OnItemDataBound(object sender, SiteMapNodeItemEventArgs e)
{
//Hiding current bread crumb node - it will be presented via ajax after page load.
SiteMapNodeItem nodeItem = e.Item;
SiteMapNode node = ((SiteMapPath)sender).Provider.CurrentNode;
// need to hide separator also, so I'm looking for current node index to compare to SiteMapNodeItem.ItemIndex
// same index will be for node and separator.
if ((node != null) && (node.ParentNode != null))
{
int index = 0;
do
{
node = node.ParentNode;
index++;
} while (node.ParentNode != null);
if (nodeItem.ItemIndex == index)
{
nodeItem.Visible = false;
}
}
}
Thanks for your self-answer, it helped me get started and then I tweaked it and think this code is a little cleaner. Though I didn't analyze it deeply, I think it will run faster since it will only run once when the final node (SiteMapNodeItemType.Current) is bound whereas your code is iterating through that loop each time the event is fired.