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

Forums / Designing with Sitefinity / Select pages to show in a menu

Select pages to show in a menu

2 posts, 0 answered
  1. Bobby Bowden
    Bobby Bowden avatar
    1 posts
    Registered:
    21 Aug 2008
    10 Jul 2009
    Link to this post
    I want to setup a page with two menus on it.  For one menu I want to pick several pages to show in it and the same for the other menu.  I know you can show all the items that are flagged as "Show in navigation" but I have discovered a way to pick only certain pages from that collection.
    Also I want to avoid hardcoding a ascx control to accomplish this.  Does anyone have any advice?
  2. Pepi
    Pepi avatar
    981 posts
    Registered:
    08 Dec 2016
    16 Jul 2009
    Link to this post
    Hello Bobby Bowden,

    You could use some of the page properties to mark that a given page should be displayed in menu1 or in menu2. For example you could use another URL option (Pages > Properties > More options > Page URLs): ~/menu1/mypage.aspx. Then, in OnItemDataBound event handler of the RadMenu, you should check the value of the page URLs and depending on this display or hide the menu item. Here is a simple example:

    public void RadMenu1_ItemDataBound(object sender, RadMenuEventArgs e) 
        { 
            CmsSiteMapNode node = e.Item.DataItem as CmsSiteMapNode; 
            if (node != null
            { 
                IList pageUrls = node.GetCmsPage().Urls; 
                bool displayInMenu1 = false
                foreach (CmsUrl url in pageUrls) 
                { 
                    if (url.Url.Contains("menu1")) 
                    { 
                        displayInMenu1 = true
                        break
                    } 
                } 
     
                if (displayInMenu1) 
                { 
                    e.Item.Visible = true
                } 
                else 
                { 
                    e.Item.Visible = false
                } 
     
                // save the PageID in the attributes of the menu item 
                e.Item.Attributes.Add("PageID", node.PageID.ToString()); 
     
                if (this.hideUrlForGroupPages) 
                { 
                    if (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.PageType == CmsPageType.Group) 
                    { 
                        if (item.Attributes["PageID"].Equals(currentNode.PageID.ToString())) 
                        { 
                            item.CssClass = this.selectedItemCssClass; 
                        } 
                    } 
                    else 
                    { 
                        // here you can set the style for the top-level item    
                        item.CssClass = this.selectedItemCssClass; 
                    } 
                } 
            } 
        } 
     
        private int GetDeepestLevel() 
        { 
            int deepestLevel = 0; 
            foreach (RadMenuItem item in this.RadMenu1.Items) 
            { 
                if (item.Level > deepestLevel) 
                    deepestLevel = item.Level; 
            } 
            return deepestLevel; 
        } 

    Let us know if this helps.

    Sincerely yours,
    Pepi
    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.
2 posts, 0 answered