views:

140

answers:

1

Hi all,

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

+2  A: 

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>
Nick Craver
HtmlEncode="false" did the trick, thanks a lot for that tip.
Melt