How do I add HTML to a ListItem in ASP/VB.net?
If I use this code on my aspx page:
<asp:BulletedList ID="listClientContacts" runa开发者_如何学JAVAt="server">
<asp:ListItem><b>My Name</b></asp:ListItem>
</asp:BulletedList>
The text renders as literal <b>My Name</b>
instead of making the text bold. The same thing happens if I try to add a list item from the VB side of things:
Dim li As ListItem = New ListItem("<b>My Name</b>")
Me.listClientContacts.Items.Add(li)
Is there a way to add HTML to a ListItem in ASP, or is there a better way to dynamically generate a list?
Is your list from a data-source? If so, then just use a repeater
<ul>
<asp:Repeater runat="server" DataSourceID="sqlDataSource1">
<ItemTemplate>
<li><b><asp:Literal runat="server" Text=<%#Eval("Field") %>></asp:Literal></b></li>
</ItemTemplate>
</asp:Repeater>
</ul>
精彩评论