开发者

How do I add HTML to a ListItem in ASP/VB.net?

开发者 https://www.devze.com 2023-01-06 00:15 出处:网络
If I use this code on my aspx page: <asp:BulletedList ID=\"listClientContacts\" runa开发者_如何学JAVAt=\"server\">

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>
0

精彩评论

暂无评论...
验证码 换一张
取 消