开发者

How do I encode HTML in an ASP.NET repeater?

I have an ASP.NET repeater pulling comment data from a database.

In my ItemTemplate I placed some Label server controls bound to the fields (username of poster, d开发者_开发技巧ate, and post text), but apparently Label does not run the data through HtmlEncode before displaying it.

Is there another control I should use? How should I display HTML-encoded data from a repeater?


What about literal with mode="encode"

<asp:Literal ID="Literal1" runat="server" Mode="Encode" />


You can use the literal control which has a mode property with enumeration Encode,PassThrough,Transform.


This has worked for me:

<%# Server.HtmlDecode(DataBinder.Eval(Container.DataItem, "ItemName")) %>


I'm assuming you want to be able to display the comments in html (with formatting et al).

replace the Label control with an Literal control. They both have the Text property but the control will handle your html content.

<asp:Literal>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜