简体   繁体   中英

How to convert plain text to html and assign it to an <li> in c#

I have a string with html content as follows:

string eg = "hi..how <b>are</b> you?"

I am assigning this string value to the text property of a bulleted list as follows:

lst.Text = eg;

The purpose is to display "are" in bold. But currently it displays the string as it is. What property of the bulleted list is to be used to render the html controls in the string? Any help is appreciated.

You will need to use an Repeater instead of a Bulleted List as bulleted list
doesn't support HTML for its ListItems

Similar questions can help you

Programmatically adding a hyperlink to a bulleted list that IS NOT DisplayMode=Hyperlink

Customized bulleted list items in ASP.NET

And this channel9 msdn page

http://channel9.msdn.com/Forums/TechOff/257894-aspnet-BulletedList-list-item-with-HTML-

Quoting from above

Try using a Repeater. The BulletedList unfortunately doesn't support HTML for its ListItems.

Markup

<asp:Repeater ID="Repeater1" runat="server">
    <HeaderTemplate><ul></HeaderTemplate>
    <ItemTemplate><li><span class="label">Test</span> <%# Container.DataItem %></li></ItemTemplate>
    <FooterTemplate></ul></FooterTemplate>
</asp:Repeater>

C#

Repeater1.DataSource = items;
Repeater1.DataBind();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM