populate a html list control using .NET

前端 未结 4 691
暗喜
暗喜 2021-02-06 05:13

I have a list defined like so:

  • Item 1
4条回答
  •  走了就别回头了
    2021-02-06 05:58

    You could use asp:BulletedList like

    
      
    
    

    Add add code like

    ListItem item = new ListItem("Item2");
    item.Attributes.Add("class", "MyClass");
    MyList1.Items.Add(item);
    

    Or if for some specific reason you need to use the ul tag then you can add a runat="server" to it. E.g.

    • Item1

    With code like

    HtmlGenericControl li = new HtmlGenericControl("li");
    li.Attributes.Add("class", "MyClass");
    li.InnerText = "Item2";
    MyList2.Controls.Add(li);
    

提交回复
热议问题