Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
i want to generate dynamic menu from database; i can generate one submenu; but i want to generate submenu under submenu like this

Menu>>
SubMenu1>>
SubMenu2>>SubMenu2a
.............SubMenu2b

I have tried this following code..to generate one submenu..
DataSet ds = new DataSet();
        DataTable dt = new DataTable();
        string sql = "Select * from Menu";
        SqlDataAdapter da = new SqlDataAdapter(sql, con);
        da.Fill(ds);
        dt = ds.Tables[0];
        DataRow[] drowpar = dt.Select("ParentID=" + 0);

        foreach (DataRow dr in drowpar)
        {
            menuBar.Items.Add(new MenuItem(dr["MenuName"].ToString(), dr["MenuID"].ToString(), "", dr["MenuLocation"].ToString()));
        }

        foreach (DataRow dr in dt.Select("ParentID >" + 0))
        {
            MenuItem mnu = new MenuItem(dr["MenuName"].ToString(), dr["MenuID"].ToString(), "", dr["MenuLocation"].ToString());
            
                menuBar.FindItem(dr["ParentID"].ToString()).ChildItems.Add(mnu);
            
        }



Database structure is like this:
MenuID MenuName MenuLocation ParentID
1 Menu AA 0
2 SubMenu1 AB 1
3 SubMenu2 AC 1
4 SubMenu2a AD 3
5 SubMenu2b AE 3

Can anyone guide me how to generate submenu under a submenu?
Posted
Updated 28-Jun-12 22:35pm
v2
Comments
Shahin Khorshidnia 29-Jun-12 2:17am    
Please tag your question. WinForm? WPF? ASP.Net? ...

Dynamic MainMenu formation in WinForm Application using DataSet
I think it works, But it's better in the database for root menu set ParentID = ID (Not null)
 
Share this answer
 
Comments
sahabiswarup 29-Jun-12 4:36am    
i want to generate submenu in web form.
 
Share this answer
 
Comments
sahabiswarup 29-Jun-12 4:37am    
i want to generate dynamic submenu in web form, but Vani i've tried the above links..if there is any other solution please share
 
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