views:

1355

answers:

2

I need to produce with asp.net controls this structure, but ListItem doesn't allow add properties and classes.

What is the best way to do it?

<ul>
 <li class="1">SomeText</li>
 <li class="2">SomeText2</li>
</ul>
+1  A: 

You can still add custom attributes:

// assuming li is your WebControl or HtmlControl:
li.Attributes.Add("class", "1");
Jeff Meatball Yang
How can he specify different classes for each list item with this code?
rahul
+3  A: 

You can pass-through class attribute:

<asp:BulletedList ID="BulletedList1" runat="server">
  <asp:ListItem class="1">SomeText</asp:ListItem>
  <asp:ListItem class="2">SomeText2</asp:ListItem>
</asp:BulletedList>

. . .

protected void Page_Load(object sender, EventArgs e)
{
   ListItem listItem = new ListItem("Test 3");
   listItem.Attributes.Add("class", "3");
   BulletedList1.Items.Add(listItem);
}
Pavel Chuchuva