Search code examples
c#asp.netbulletedlist

How to add element inside ListItem in code behind?


I want to add something like this in the code behind:

<ul>
   <li><a>A</a></li>
</ul>

However, the ListItem of ASP.NET seems to allow text only:

BulletedList UserSubMenuList = new BulletedList();
ListItem EditUserItem = new ListItem("Edit Profile"); 

Is there other way to add content between <li></li> tag with code behind rather then using HtmlGenericControl?


Solution

  • Front :

    <ul id="test" runat="server">
    
    </ul>
    

    Back:

    Label label1=new Label();
    
    label1="test";
    
    test.Controls.Add(new LiteralControl("<li>")); 
    
    test.Controls.Add(label1); 
    
    test.Controls.Add(new LiteralControl("</li>"))