Add to List from codebehind C# Asp.net

后端 未结 5 1140
春和景丽
春和景丽 2020-12-09 03:10

I have a UL list in a ASPX page:

  • Tab 1
5条回答
  •  再見小時候
    2020-12-09 03:27

    You need to mark your ul as a server side control, then treat the 'new item' as a HtmlGenericControl and insert it into the control collection:

    To add the item, create a new element and add it:

    HtmlGenericControl li = new HtmlGenericControl("li");
    tabs.Controls.Add(li);
    
    HtmlGenericControl anchor = new HtmlGenericControl("a");
    anchor.Attributes.Add("href", "page.htm");
    anchor.InnerText = "TabX";
    
    li.Controls.Add(anchor);
    

提交回复
热议问题