1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Simple Menu Control?

Simple Menu Control?

4 posts, 1 answered
  1. Jay
    Jay avatar
    51 posts
    Registered:
    16 Jul 2008
    23 Feb 2009
    Link to this post
    I'm trying to create a very simple left-side menu and having more problems than I would've thought.  I have everything controlled by CSS so all I need the control to output is a bulleted list like this:

                    <ul>
                        <li><a href="">Who We Are</a></li>
                        <li><a href="">Our Work</a></li>
                        <li><a class="selected" href="">Frequently Asked Questions</a></li>
                    </ul>

    I'm using a Site Menu control and I've turned off the skin and added my "selected" class which gets me 90% there.  No matter what page I'm on though, the first link ALWAYS has the selected class.  I can't figure out how to turn it off.

    I have my pages like this:
    About Us (page group)
      - Who We are
      - Our Work
      - Frequently Asked Questions

    Does the first link always being selectedhave something to do with it being the first page in a page group?

    I also have:
    StartingNodeOffset: 0
    ShowStartingNode: False
    StartFromCurrentNode: False
    StartingNodeUrl: ~/about-us.aspx (which is the name of the page group)

    How can I make sure that the is only applied to the actual current page?
    Any help will be appreciated.
  2. Jay
    Jay avatar
    51 posts
    Registered:
    16 Jul 2008
    25 Feb 2009
    Link to this post
    I did some testing and the reason my first item always gets the selected class is definitely because it's the first page in a page group.  Is there any way around that?
    Perhaps some way to override that function?  Any help would be appreciated.
  3. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    25 Feb 2009
    Link to this post
    Hi Jay,

    You could try applying different styles for the grup and the first page modifying the code behind of the menu. Below is a sample:

     public void RadMenu1_ItemDataBound(object sender, RadMenuEventArgs e) 
        { 
            RadMenu radMenu = (RadMenu)sender; 
            CmsSiteMapNode node = e.Item.DataItem as CmsSiteMapNode; 
            if (node != null && SiteMap.CurrentNode == node) 
            { 
                if (node.CmsPage.PageType == CmsPageType.Group && radMenu.Items.Count > e.Item.Index) 
                    radMenu.Items[e.Item.Index + 1].CssClass = "myclass"
                else 
                    e.Item.CssClass = "myclass"

    I hope this helps.

    Best wishes,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
    Answered
  4. Jay
    Jay avatar
    51 posts
    Registered:
    16 Jul 2008
    26 Feb 2009
    Link to this post
    Thanks so much.  You guys have the best support team of any vendor I've ever worked with.  For anyone else who might be interested.  Here is my final function with the code Ivan sent added to it.

        public void RadMenu1_ItemDataBound(object sender, RadMenuEventArgs e) 
        { 
            if (this.hideUrlForGroupPages) 
            { 
                CmsSiteMapNode node = e.Item.DataItem as CmsSiteMapNode; 
                if (node != null && node.PageType == CmsPageType.Group) 
                { 
                    e.Item.NavigateUrl = ""
                } 
            } 
     
            CmsSiteMapNode currentNode = SiteMap.CurrentNode as CmsSiteMapNode; 
            if (currentNode != null && currentNode.ParentNode != null
            { 
                while (currentNode.ParentNode != SiteMap.RootNode) 
                { 
                    RadMenuItem item2 = this.RadMenu1.FindItemByUrl(this.ResolveUrl(currentNode.Url)); 
                    if (item2 != null
                        item2.CssClass = this.selectedItemCssClass; 
                    currentNode = currentNode.ParentNode as CmsSiteMapNode; 
                } 
     
                RadMenuItem item = this.RadMenu1.FindItemByUrl(this.ResolveUrl(currentNode.Url)); 
                if (item != null
                { 
                    if (currentNode.CmsPage.PageType != CmsPageType.Group) 
                    { 
                        // here you can set the style for the top-level item    
                        item.CssClass = this.selectedItemCssClass; 
                    } 
                } 
            }  
        } 

Register for webinar
4 posts, 1 answered