c# - How to create submenus from database? -


i have created menus "home""about us" on html page, want submenus of home , about us database c# code. how this?

you need table in database store menuitems. place asp.net menu control in page:

<asp:menu id="menubar" runat="server" orientation="horizontal" width="100%"> </asp:menu> 

and in code behind:

datatable dt = new datatable(); //your sql code fill dt 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); } 

read this article codeproject may you.


Comments