This is a migrated thread and some comments may be shown as answers.

Load Menu from Database

4 Answers 125 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Marcia Marino
Top achievements
Rank 1
Marcia Marino asked on 12 Feb 2014, 07:40 PM
        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);
            }
        }

4 Answers, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 17 Feb 2014, 02:54 PM
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.
0
Marcia Marino
Top achievements
Rank 1
answered on 18 Feb 2014, 04:06 AM
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.
0
Marcia Marino
Top achievements
Rank 1
answered on 18 Feb 2014, 04:09 AM
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.
0
Boyan Dimitrov
Telerik team
answered on 20 Feb 2014, 03:54 PM
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.
Tags
Menu
Asked by
Marcia Marino
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
Marcia Marino
Top achievements
Rank 1
Share this question
or