Hello
I have a master page that uses a repeater to create html anchors for the main navigation menu. I also have some css that controls the display. The anchors are databound from a web.sitemap file.
I also have exposed a property on the master page that specifies which anchor is supposed to be highlighted in the navigation menu. Content forms assign value to this property.
Here are the relevant snippets:
<div class="menu">
<ul>
<li>
<asp:HyperLink runat="server" ID="lnkHome" NavigateUrl="~/Default.aspx">Home</asp:HyperLink></li>
<asp:Repeater runat="server" ID="parentMenu" DataSourceID="mainSiteMap" EnableViewState="false">
<ItemTemplate>
<li>
<asp:HyperLink runat="server" id="parentLink" NavigateUrl='<%# Eval("Url") %>'><%# Eval("Title") %></asp:HyperLink>
<asp:Repeater ID="childMenu" runat="server" DataSource="<%# CType(Container.DataItem, SiteMapNode).ChildNodes %>">
<HeaderTemplate>
<ul>
</HeaderTemplate>
<ItemTemplate>
<li>
<asp:HyperLink runat="server" id="childLink" NavigateUrl='<%# Eval("Url") %>'><%# Eval("Title") %></asp:HyperLink></li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
</li>
</ItemTemplate>
</asp:Repeater>
</ul>
<asp:SiteMapDataSource ID="mainSiteMap" runat="server" ShowStartingNode="false" />
</div>
Private Sub parentMenu_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles parentMenu.ItemDataBound
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
If CType(e.Item.DataItem, SiteMapNode).Title = ActiveMenuSelection Then
' find the html anchor and modify attributes to trigger CSS changes
Else
lnkHome.ID = "current"
End If
End If
End Sub
What happens is I successfully match the ActiveMenuSelection property to the item_databound argument, but from there I am a little fuzzy on finding the specific control I want to modify.
Has anyone ever tried something like this?
I know that I could probably use an <asp:Menu /> control, but if there is a solution to the above, that would be better for my purposes.
Thanks in advance.
CC