Reputation: 411
I have a simple site consisting of a root site with 2 child sites.
Now I want the navigation for all 3 sites to be exactly the same and read:
Root Site | Child Site 1 | Child Site 2
With the currently selected site highlighted.
I have been able to nearly do this manually using an asp:repeater control and portalsitemapprovider. The problem is I can either get just the Root Site on the navigation (set ShowStartingNode to True) or just the child sites, I can't get both.
I know you can get both if you use a sharepoint:aspmenu control and set staticdisplaylevels to 2 but I don't like the messy code this control spits out. Basically i want to emulate this controls behaviour wrapped in my own compliant css. Any ideas?
Thanks!
Upvotes: 1
Views: 1909
Reputation: 3533
I think you have to start at the root and render that node in a first repeater and then use the childnodes of the root as a datasource for a second repeater, something like:
<asp:Repeater runat="server" ID="MenuRepeater"
DataSourceID="MainNavigationDataSource">
<HeaderTemplate>
// code here
</HeaderTemplate>
<ItemTemplate>
// code here
<asp:Repeater runat="server" ID="ChildMenuRepeater"
DataSource='<%# ((SiteMapNode)Container.DataItem).ChildNodes %>'>
<HeaderTemplate>
// code here
</HeaderTemplate>
<ItemTemplate>
// code here
</ItemTemplate>
</ItemTemplate>
For your second question, I think (if I understand it correctly) that you could use SiteMapNode.IsDescendantOf() method but I somehow recall that that will not work in SharePoint so I have used this sort of code to check if a node is the "active" node:
string CurrentContextUrl = SPUtility.GetPageUrlPath(HttpContext.Current);
Uri CurrentUri = new Uri(CurrentContextUrl);
bool Active = CurrentUri.LocalPath.Equals(currentNode.Url);
Hope it helps out somehow :-)
Upvotes: 1