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

Forums / Designing with Sitefinity / SiteMenu: Displaying Sibling links if no Children present

SiteMenu: Displaying Sibling links if no Children present

3 posts, 0 answered
  1. James Gargan
    James Gargan avatar
    3 posts
    Registered:
    12 Aug 2009
    16 Mar 2010
    Link to this post
    Hi Telerik,

    I am trying to set up a left-hand sub-navigation for our client's website. Is it possible that when there are no child pages present, that a SiteMenu control only displays the sibling pages? For example I have a Site Map such as:

    + About Us
    |----- Our Team
    |----- Directors
    |----- Contact Us

    Currently, I have a SiteMenu control to generate the menus. So when the user clicks into "About Us", they see the 3 sub-pages displayed. But (for example) when a user clicks into "Directors", the SiteMenu becomes blank, because SiteMenu will only generate a list of child pages. Is there a way to generate a dynamic menu that displays all child pages, but if there are none present it shows the sibling pages?

    I have attached the settings I am using for the SiteMenu control; I would appreciate any direction or help on if it's possible to get this effect?

    Thanks in Advance,

    James


  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    16 Mar 2010
    Link to this post
    Hello James Gargan,

    You have to create a custom RadMenu control and populate its data manually. When you click on an item that does not have items you should remain in the same level

    below is  a sample code

    protected void  Page_Load(object sender, EventArgs e)
        {
            RadMenuItemCollection items = this.FillMenu(SiteMap.CurrentNode);
            foreach (RadMenuItem item in items)
            {
                RadMenu1.Items.Add(item);
            }
        }
      
        public RadMenuItemCollection FillMenu(SiteMapNode node)
        {
            RadMenuItemCollection result = new RadMenuItemCollection(this.RadMenu1);
            if (node != null)
            {
                 
                if(node.ChildNodes.Count == 0)
                {
                    foreach (SiteMapNode child in node.ParentNode.ChildNodes)
                    {
                        RadMenuItem item = new RadMenuItem(child.Title, child.Url);
                        foreach (SiteMapNode child2 in child.ChildNodes)
                        {
                            foreach (RadMenuItem item1 in FillMenu(child2))
                            {
                                item.Items.Add(item1);
                            }
                        }
                        result.Add(item);
                    }
                }
                else
                {
                    foreach (SiteMapNode child in node.ChildNodes)
                    {
      
                        RadMenuItem item = new RadMenuItem(child.Title, child.Url);
                        foreach (SiteMapNode child2 in child.ChildNodes)
                        {
                            foreach (RadMenuItem item1 in FillMenu(child2))
                            {
                                item.Items.Add(item1);
                            }
                        }
                        result.Add(item);
                    }
                }
            }
            return result;
        }


    Regards,
    Ivan Dimitrov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. James Gargan
    James Gargan avatar
    3 posts
    Registered:
    12 Aug 2009
    18 Mar 2010
    Link to this post
    Hi Ivan,

    Thanks for the prompt reply; we will create that new control and see how that works. Thanks for your help :)
Register for webinar
3 posts, 0 answered