2

I have following sitemap defined:

<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
  <siteMapNode url="" title="Root" roles="*">
    <siteMapNode url="~/Default.aspx" title="Home" roles="*" />
    <siteMapNode url="~/ProjectList.aspx" title="Projects" roles="*">
      <siteMapNode url="~/ProjectOverview.aspx" title="Project Overview"  roles="*" />
      <siteMapNode url="~/ProjectViewCalls.aspx" title="View Calls" roles="*" />
    </siteMapNode>
    <siteMapNode url="~/Configuration.aspx" title="Configuration" roles="Administrator" />
    <siteMapNode url="~/YourAccount.aspx" title="Your Account" roles="Administrator" />
    <siteMapNode url="~/Logout.aspx" title="Logout" roles="*" />
  </siteMapNode>
</siteMap>

I need this to display in my menu control as: Home | Projects | Configuration | Your Account | Logout.

This is working correctly however when i navigate to the pages ProjectOverview and ProjectViewCalls, I lose the selected class="level1 selected" attribute of the list item. I want to be able to indicate what area of the site the user is currently in.

Is this possible?

Ant Swift
  • 20,089
  • 10
  • 38
  • 55

2 Answers2

0

I have written a detailed article for this at codeproject ( http://www.codeproject.com/Articles/669717/How-to-correctly-use-sitemap-for-top-left-menus ) and here ( http://mangeshdevikar.enziq.com/how-to-correctly-use-sitemap-for-topleft-menus/ ) . Hope it helps.

  • Please, try to read this http://stackoverflow.com/help/deleted-answers, to get more understanding how to **not** answer. Namely: "Answers that do not fundamentally answer the question": **barely more than a link to an external site** – Radim Köhler Oct 29 '13 at 06:17
0

Not sure if this is what you're looking for, but here is an easy way to do it. Add a MenuItemDataBound event to the menu control, then in the event use this code:

        if(e.Item.Selected)
        {
            if(e.Item.Parent != null && e.Item.Parent.Selectable)
            {
                e.Item.Parent.Selected = true;
            }
        }

If you do this, the current menu item will not have the selected style, so it might mess up your pop-out sub menu.

If the child nodes aren't being displayed at all, you could try binding something like this on MenuDataBound:

var myMenu = (Menu) sender;
var currentNode = SiteMap.Provider.FindSiteMapNode(HttpContext.Current);
if (currentNode != null)
{
    var parentMenuItem = myMenu.FindItem("Root/" + currentNode.ParentNode.Title);
    if (parentMenuItem != null && parentMenuItem.Selectable)
    {
        parentMenuItem.Selected = true;
    }
}

Another option would be to ditch the default menu script and use something like Superfish instead.

Walter
  • 1,855
  • 18
  • 29
  • I'm not using a sub menu, the reason for the sub nodes in my sitemap are because i want all the projects related pages to have the projects menu item selected. When navigating to one of the 'sub pages', e.Item.Selected is never true. – Ant Swift Nov 03 '10 at 15:19
  • Oh ok. In that case maybe something like this on MenuDataBound: 'var currentNode = SiteMap.Provider.FindSiteMapNode(HttpContext.Current); if (currentNode != null) { var parentMenuItem = Menu1.FindItem("Root/" + currentNode.ParentNode.Title); if (parentMenuItem != null && parentMenuItem.Selectable) { parentMenuItem.Selected = true; } }' – Walter Nov 03 '10 at 21:37