Click to See Complete Forum and Search --> : Create dynamic menu in web application


NamrataC
June 18th, 2009, 07:02 AM
Hi All,

I'm trying to create a master page with menu control that will populated dynamically from the database. While populating menu I don't wish create an XML file for the purpose.

dannystommen
June 18th, 2009, 08:26 AM
you can use the asp:Literal control to apply dynamic html


StringBuilder menu = new StringBuilder();
menu.AppendLine("<ul>");

List<MyObject> list = SelectDataFromDB();
foreach(MyObject o in list){
menu.AppendLine(string.Format("<li><a href=\"{0}\">{1}</a></li>", o.Url, o.Text)); //asuming that Url and Text are values you select from the DB
}

menu.AppendLine("</ul>");

literalMenu.Text = menu.ToString();