Populating RadMenu from both sitemap and database

2 posts, 0 answers
  1. Aaron
    Aaron avatar
    6 posts
    Member since:
    Sep 2015

    Posted 03 Apr 2018 Link to this post

         I'd like to populate my menu from the sitemap, utilizing the SecurityTrimmingEnabled feature, and also add some additional menu nodes from a database.


    Before I added the sitemap and SecurityTrimming I was doing this to dynamically add records to my Help menu.  Now it's not adding the child menus.


    private void LoadHelpMenu()
                List<HelpDocumentation> menuItems = new List<HelpDocumentation>();
                menuItems = BaseUserProcess.GetHelpMenuItems();

                if (menuItems != null)
                    RadMenuItem HelpMenu = radMenuNavigation.Items.Where(f => f.Text == "Help").FirstOrDefault();
                    HelpMenu = LoadMenuNode(menuItems, HelpMenu);

                    string version = typeof(WorkBench).Assembly.GetName().Version.ToString();
                    RadMenuItem Appversion = new RadMenuItem("Version: " + version);
                    radMenuNavigation.Items.Where(f => f.Text == "Help").FirstOrDefault().Visible = false;


            private RadMenuItem LoadMenuNode(List<HelpDocumentation> menuItems, RadMenuItem node, int? ParentID = null)
                List<HelpDocumentation> GroupingItems = new List<HelpDocumentation>();
                if (ParentID == null)
                    GroupingItems = menuItems.Where(F => F.ParentID.HasValue == false).ToList();
                    GroupingItems = menuItems.Where(F => F.ParentID == ParentID).ToList();

                foreach (var item in GroupingItems.OrderBy(F => F.DisplayDescription).ToList())
                    RadMenuItem i = new RadMenuItem(item.DisplayDescription);
                    if (!string.IsNullOrEmpty(item.Link))
                        i.NavigateUrl = item.Link;
                    if (!string.IsNullOrEmpty(item.Target))
                        i.Target = item.Target;
                    if (menuItems.Any(F => F.ParentID == item.ID))
                        i = LoadMenuNode(menuItems, i, item.ID);
                return node;

  2. Marin Bratanov
    Marin Bratanov avatar
    5614 posts

    Posted 06 Apr 2018 Link to this post

    Hello Aaron,

    I do not see anything obviously wrong with this code. Can you step through it and see what the collections hold and how looping through them goes in both cases? Perhaps something goes amiss with the data source and the loops do not get executed.

    I can also suggest you look into reading the sitemap programmatically and create all menu items programmatically instead of using data binding.

    Another test you can run is:

    1. take the sample from this post: https://www.telerik.com/forums/multi-column-amp-sitemap-datasource#DIcRKiCLGE2vpaOrgg-KOg
    2. make the menu add data bound items:
      <telerik:RadMenu ID="RadMenu1" runat="server" DataSourceID="SiteMapDataSource1" Skin="Telerik" AppendDataBoundItems="true">
    3. add items:
      protected void Page_Load(object sender, EventArgs e)
          if (!Page.IsPostBack)
              RadMenu1.Items.Add(new Telerik.Web.UI.RadMenuItem("test item"));


    Marin Bratanov
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top