Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net: DetailsView control not interpreting html

I have a asp.net detailsview control on a page. I've noticed that it always displays the raw text from my database field, it doesn't interpret the html in the text -- so it displays < b>mytext< /b> instead of just mytext in bold.

Is there anyway to get the control to interpret the html in the data being returned

Regards melt

like image 563
Melt Avatar asked Jan 10 '10 15:01

Melt


1 Answers

Can you post the code of your control? The basics are you need to set the HtmlEncode property to false. This is due to a difference in how labels and textboxes handle encoding, something meant to protect you from malicious scripts someone may have entered in these fields.

If you have it set to auto-generate fields (default), you'll need to change to BoundFields or TemplateFields instead and set the offending field's HtmlEncode Property to false.

You can see a code sample of the individual fields in MSDN, here's a simplified example:

<asp:DetailsView runat="server" AutoGenerateRows="False">
  <Fields>
    <asp:BoundField DataField="ProductName" HeaderText="Product" />
    <asp:BoundField DataField="CategoryName" HeaderText="Category" />
    <asp:BoundField DataField="HTMLField" HeaderText="HTML" HtmlEncode="false" />
  </Fields>
</asp:DetailsView>
like image 183
Nick Craver Avatar answered Oct 25 '22 12:10

Nick Craver