Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
SharePoint 2010 top level navigation code. Built with a nested ASP:Repeater control. Easier to style with Bootstrap or Flexbox than the ASP:Menu control. Includes highlighting of the current section.
<!-- top navigation publishing data source -->
<PublishingNavigation:PortalSiteMapDataSource
id="topSiteMap"
runat="server"
EnableViewState="false"
SiteMapProvider="GlobalNavigation"
StartFromCurrentNode="false"
StartingNodeOffset="0"
ShowStartingNode="true"
TrimNonCurrentTypes="Heading"/>
<!--
Repeater outputs a single level list of top-navigation.
Sets class="selected" on the current page / site.
This is much easier to adapt to use with Bootstrap or flexbox than the asp:menu control.
Based on a post by Bhavin Prajapati - http://sharepoint2010customnavigation.blogspot.co.uk/2011/05/create-custom-navigation-for.html
-->
<asp:Repeater runat="server" ID="MenuRepeater" DataSourceID="topSiteMap">
<HeaderTemplate>
<ul>
</HeaderTemplate>
<SeparatorTemplate></SeparatorTemplate>
<ItemTemplate>
<li>
<a href="<%# Eval("Url")%>"
class="<%# (Request.RawUrl.ToString().ToLower().Split('/')[1] == Eval("Url").ToString().ToLower().Split('/')[1]) ? "selected" : "" %>">
<%# Eval("Title")%>
</a>
</li>
<asp:Repeater runat="server" ID="ChildMenuRepeater" DataSource='<%# ((SiteMapNode)Container.DataItem).ChildNodes %>'>
<HeaderTemplate></HeaderTemplate>
<ItemTemplate>
<li>
<a href="<%# Eval("Url")%>"
class="<%# (Request.RawUrl.ToString().ToLower().Split('/')[1] == Eval("Url").ToString().ToLower().Split('/')[1]) ? "selected" : "" %>">
<%# Eval("Title")%>
</a>
</li>
</ItemTemplate>
<FooterTemplate></FooterTemplate>
</asp:Repeater>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.