tags:

views:

58

answers:

4

I know the soultion must be simple. but i can't figure this up.

i want to add list item programatically with html tags inside the li

string x = "xxxx <br/> yyyy"

BulletedList.items.add(x)

i want to see

  1. xxx
    yyy

and not

  1. xxx< br / > yyy

please help

A: 

Get rid of the <br /> tag.

Rex M
but i want to <br> or any other tag inside the listitem
maggie
i edited my question again
maggie
@Maggie it's generally bad form to downvote people who didn't give you the answer you were looking for because your question was wrong.
Rex M
A: 

Remove the </BR> tag as below:

string x = "xxxx yyyy"

devcoder
@maggie, you never mentioned in your question that you want BR tag. If this is the case than @kbrimington's solution is the right choice. You would have read your question again before down voting the answer.
devcoder
+2  A: 

To have greater flexibility over the HTML rendered on each list element, consider using a Repeater or a ListView instead. They require a little more HTML to set up your <ul> and <li> tags, but will give you arbitrary flexibility over the contents of the <li>.

<ul>
<asp:Repeater ID="repeater" runat="server">
    <ItemTemplate>
    <li>
        <div>Any HTML or data binding you want.</div>
    </li>
    </ItemTemplate>
</asp:Repeater>
</ul>
kbrimington
A: 

The BulletedList control will strip any html you put in it. You will have to subclass it and override it's render method to achieve this.

I use the following to associate a CssClass with the items in the list, which I can then use to pretty them up.

public class CustomBulletedList : BulletedList
{
    protected override void Render(HtmlTextWriter writer)
    {
        var sb = new StringBuilder();
        var sw = new StringWriter(sb);
        var htmlWriter = new HtmlTextWriter(sw);
        base.Render(htmlWriter);
        sb = sb.Replace("&lt;div class=notes&gt;", "<div class=notes>");
        sb = sb.Replace("&lt;/div&gt;", "</div>");
        writer.Write(sb.ToString());
    }
}
WOPR