How to render decoded HTML in a (i.e. a <br>) in GridView cell

core picture core · Jan 10, 2009 · Viewed 54.9k times · Source

I'm binding a GridView to an LINQ query. Some of the fields in the objects created by the LINQ statement are strings, and need to contain new lines.

Apparently, GridView HTML-encodes everything in each cell, so I can't insert a <br /> to create a new line within a cell.

How do I tell GridView not to HTML encode the contents of cells?

Maybe I should use a different control instead?

Answer

Aaron Daniels picture Aaron Daniels · Apr 2, 2010

What about setting the HtmlEncode property to false? To me, this is much simpler.

<asp:BoundField DataField="MyColumn" HtmlEncode="False" />