Biswarup Saha

Biswarup Saha

  • NA
  • 58
  • 31.3k

How to generate Horizontal submenu from database?

Jun 29 2012 1:14 AM
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?