asp.net: DetailsView control not interpreting html
Asked Answered
F

1

5

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

Farrago answered 10/1, 2010 at 15:9 Comment(0)
P
8

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>
Pair answered 10/1, 2010 at 15:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.