CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2009
    Posts
    3

    Create dynamic menu in web application

    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.

  2. #2
    Join Date
    Sep 2008
    Location
    Netherlands
    Posts
    865

    Re: Create dynamic menu in web application

    you can use the asp:Literal control to apply dynamic html

    Code:
    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();

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured