I have a GridView bound to a DataTable that I construct. Most columns in the table contain the raw HTML for a hypelinklink, and I would like that HTML to render as a link in the browser, but the GridView is automatically encoding the HTML, so it renders as markup.
How can I avoid this without explicitly adding HyperLink, or any other, columns?
Simply set theBoundColumn.HtmlEncodeproperty to false:<asp:BoundField DataField="HtmlLink" HtmlEncode="false" />I am afraid that there is no easy way to disable HTML encoding of the contents in a
GridViewwithAutoGenerateColumns= true. However, I can think of two workarounds that might solve the problem you are facing:Option 1: Inherit the
GridViewclass, override theRendermethod, loop through all cells, decode their contents, before executing the base method:Option 2: In a class inheriting from
GridViewor in thePageorControlusing it, make your own inspection of theDataTableand create an explicitBoundColumnfor each column: