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

Forums / Developing with Sitefinity / TopMenu / Panelbar Selected TopMenu Item CSS

TopMenu / Panelbar Selected TopMenu Item CSS

4 posts, 0 answered
  1. Markus
    Markus avatar
    2763 posts
    Registered:
    25 Nov 2005
    11 Sep 2009
    Link to this post
    Hi there

    I have a SiteMenu on top of my page on which I show only the TopLevel Pages (Level 0)

    I then have a PanelBar on the left side of each page showing the corresponding Level 1 - Level n depending on the Selected Level0 from the topmenu.

    What I want is to give the TopLevel0 Item that has been selected a special look.

    LEVEL 0 MenuSite Items  = Home | Products | Locations

    PanelBar Level Items

    Product 1
    Product 2

    Location 1
    Location 2

    So what I want is that if I click on Home - it will have a selectClass
    If I click on Product 1 or Product 2 in the Panelbar , Products from the SiteMenu will have this selectedClass

    How do I go about it. Read some post but could not quite get it in the right direction?

    Any help
    Regards Markus
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    11 Sep 2009
    Link to this post
    Hello Markus Berchtold,

    Subscribe for DataBound event of RadMenu and add the logic below. This will style the root node when you click in the corresponding child ( or root )node of your RadPanelBar.

      public void RadMenu1_DataBound(object sender, EventArgs e) 
        { 
            CmsSiteMapNode topLevelNode = SiteMap.CurrentNode as CmsSiteMapNode; 
            while (topLevelNode != null
            { 
                if (topLevelNode.Parent == null
                    break
                topLevelNode = (CmsSiteMapNode)topLevelNode.Parent; 
            } 
            var currentUrl = topLevelNode.Url; 
            // use Linq 
            var menuItem = this.RadMenu1.GetAllItems().AsQueryable().Where(i => i.NavigateUrl == currentUrl).Single(); 
            menuItem.CssClass = selectedItemCssClass; 
        } 


    Regards,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Markus
    Markus avatar
    2763 posts
    Registered:
    25 Nov 2005
    12 Sep 2009
    Link to this post
    Dear Ivan

    Unfortunately I get the following error on all pages that contain any child

    Sequence contains no elements

    The only one it works is home where I have not pages under it.

    Any idea?

    Regards Markus
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    16 Jun 2017
    13 Sep 2009
    Link to this post
    Hi Markus Berchtold,

    I am not getting any errors on the local project. Can you send the stack trace? The error is thrown from LINQ. You can try using  SingleOrDefault() that returns a null value if there are no source records that matches to the filtering criteria. You can also attach the code to debugger to see the exact error.

    For more information, please take a look at MSDN - Enumerable.Single Method,
    Enumerable.SingleOrDefault Method

    Sincerely yours,
    Ivan Dimitrov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Register for webinar
4 posts, 0 answered