Click here to Skip to main content
15,878,430 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have these 2 table for menu Making

**Pages**
PathId
ParentId
PathUrl
PathName

**PagesAssigned**
AssignedId
PathId
RoleId



SQL
SELECT [Path].Menu_Id,dbo.[Path].Path_Detail,
    [Path].Path_Url, [Path].Sub_Menu_Id,
    pagesAssigend.roleId
   FROM  pagesAssigend INNER JOIN [Path]
         ON pagesAssigend.pageNo = Path.Menu_Id
   WHERE (dbo.pagesAssigend.roleId = 1)


Through above query i confirming a menu for a specified user using hir\her role id.
and in aspx file i have this code to fill asp menu control

C#
 int RoleNo = Convert.ToInt16(Session["RoleId"]);
                    objLogin.Role_Id =  RoleNo;
                    DataTable dt = new DataTable();
                    dt = objLogin.MenuMaking();
                    GridView1.DataSource = dt;
                    GridView1.DataBind();
                    foreach (DataRow dr in dt.Rows)
                    {
                        MenuItem objMenuItem = new MenuItem();
                        objMenuItem.Text = dr["Path_Detail"].ToString();
                        objMenuItem.NavigateUrl = dr["Path_Url"].ToString(); 
                        MenuBar.Items.Add(objMenuItem);
                    }


this is working fine but i want to show child menu too under it parent menu. How can i acheive this??
Posted

1 solution

to have submenus you just add menuItems to a menuItems ChildItems.

// Retrieve the root menu item from the Items
     // collection of the Menu control using the indexer.
     MenuItem homeMenuItem = NavigationMenu.Items[0];

     // Create the submenu item.
     MenuItem newSubMenuItem = new MenuItem("New Category");

     // Add the submenu item to the ChildItems
     // collection of the root menu item.
     homeMenuItem.ChildItems.Add(newSubMenuItem);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900