-1

The above is the code in my .aspx page. How this can be added from code behind dyanmically?

<ul runat="server" id="1">
<li><a href="page.html">abc</a>
  <ul runat="server" id="2">
  <li><a href="pag2.htm">3</a></li>
  <li><a href="page3.htm">2</a></li>
  </ul>
</li>
</ul>
Community
  • 1
  • 1
Satya
  • 23
  • 1
  • 2
  • 12
  • I'd suggest using a repeater with a nested bulletedlist control. But I hope the data is only one level deep...? – deostroll May 28 '14 at 13:28

4 Answers4

0

You must use the "InnerHtml" property of "sidebarmenu1" control.

protected void Page_Load(object sender, EventArgs e)
        {
            this.loadHtml();
        }

So you can generate every list item code and add it to the InnerHtml:

private loadHtml()
{
    this.sidebarmenu1.InnerHtml = GetListHtml().ToHtmlString();
}

And a little example for this GetListHtml:

public string GetListHtml()
        {
            StringBuilder htmlBuilder = new StringBuilder();

            htmlBuilder.AppendLine("<li><a href="#">Flat</a>");
            htmlBuilder.Append("<ul runat="server" id="sidebarmenu2">");
            htmlBuilder.AppendLine("<li><a href="#">Flat 1`enter code here`</a></li>");
            htmlBuilder.Append("<li><a href="#">Flat 2</a></li></ul>");
            return htmlBuilder.ToString();
        }

This GetListHtml method can call to a DAL or load data from any other place... use a foreach to load every item...

zapico
  • 2,396
  • 1
  • 21
  • 45
  • i guess the string (attribute values) you have enclosed in double quotes will not work. eg:htmlBuilder.AppendLine("
  • Flat"); must be replaced with htmlBuilder.AppendLine("
  • Flat"); the attribute values must be enclosed with single quotes right?
  • – SHEKHAR SHETE Apr 28 '14 at 04:20