Load Menu from Database

5 posts, 0 answers
  1. Marcia Marino
    Marcia Marino avatar
    22 posts
    Member since:
    Jan 2006

    Posted 12 Feb 2014 Link to this post

            The root is loading fine but I get just the last child item
    Can anyone help me, please

             public void Page_Init(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    // Do something resource-intensive that you only want to do on GETs
                    DataTable dtMenu = SplendidCache.TabMenu();                // Hide the tab menu if there is no menu to display.
                    // This should only occur during login.
                    if (dtMenu.Rows.Count == 0)
                    {
                        this.Visible = false;
                        return;
                    }
                    for (int nRow = 0, nDisplayedTabs = 0; nRow < dtMenu.Rows.Count; nRow++)
                    {
                        DataRow row = dtMenu.Rows[nRow];
                        string strModuleName = Sql.ToString(row["MODULE_NAME"]);
                        string strRelativePath = Sql.ToString(row["RELATIVE_PATH"]);
                        string strDisplayName = Server.HtmlEncode(L10n.Term(Sql.ToString(row["DISPLAY_NAME"])));                    RadMenuItem child = new RadMenuItem();
                        child.Text = strDisplayName;
                        child.Value = strModuleName;
                        child.NavigateUrl = strRelativePath;                    SMGMenu.Items.Add(child);                    if (!String.IsNullOrEmpty(strModuleName))
                        {
                            ChildMenu(strModuleName, child);
                        }
                    }
                    SMGMenu.DataBind();
                }
            }        public void ChildMenu(string parent, RadMenuItem menuItem)
            {
                DataTable dtShortcuts = SplendidCache.Shortcuts(parent);
                RadMenuItem subChild = new RadMenuItem();            string strSubRelatedPath = String.Empty;
                string strSubDisplayName = String.Empty;
                string strSubModuleName = String.Empty;            if (dtShortcuts.Rows.Count > 0)
                {
                    foreach (DataRow rowShortcuts in dtShortcuts.Rows)
                    {
                        strSubRelatedPath = Sql.ToString(rowShortcuts["RELATIVE_PATH"]);
                        strSubDisplayName = Server.HtmlEncode(L10n.Term(Sql.ToString(rowShortcuts["DISPLAY_NAME"])));
                        strSubModuleName = Sql.ToString(rowShortcuts["MODULE_NAME"]);                    subChild.Text = strSubDisplayName;
                        subChild.Value = strSubModuleName;
                        subChild.NavigateUrl = strSubRelatedPath;                    if ((!String.IsNullOrEmpty(parent)) && (!String.IsNullOrEmpty(strSubModuleName)))
                        {
                            if (parent.ToLower() != strSubModuleName.ToLower())
                            {
                                ChildMenu(strSubModuleName, subChild);
                            }
                        }
                        menuItem.Items.Add(subChild);
                    }
                    SMGMenu.Items.Add(menuItem);
                }
            }
  2. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 17 Feb 2014 Link to this post

    Hello,

    Please try the suggested approach shown in this help article for populating the RadMenu control from the code behind.


    Regards,
    Boyan Dimitrov
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the UI for ASP.NET AJAX, subscribe to the blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Marcia Marino
    Marcia Marino avatar
    22 posts
    Member since:
    Jan 2006

    Posted 17 Feb 2014 in reply to Boyan Dimitrov Link to this post

    Thank you but it does not work, as I get a error that no all values have corresponding parent value, also I need to validate if user has access to the that list and is a multilingual app.
  5. Marcia Marino
    Marcia Marino avatar
    22 posts
    Member since:
    Jan 2006

    Posted 17 Feb 2014 in reply to Boyan Dimitrov Link to this post

    Sorry doesn't work get an error that not all values has corresponding parent, also I need to validate if user has access to each tab and is a multilingual app.
  6. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 20 Feb 2014 Link to this post

    Hello,

    Please find attached a sample page that implements the approach shown in the help article.

    Regards,
    Boyan Dimitrov
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the UI for ASP.NET AJAX, subscribe to the blog feed now.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017