C# Tip - Rendering HTML in a Gridview cell
- by BobPalmer
Just a quick tip for working with the gridview in ASP.Net. If your data column contains HTML text, you've probably seen something like this in your gridview after pulling the data:
<font color="red">First Item</font><br/><font color="green">Second Item</font><br/><font color="blue">Third Item</font>
To have the relevant column render in HTML, just go to your gridview property pages, find the column you need rendered in HTML, and click 'convert this Field into a TemplateField'. The result is that as a template field, HTML within your bound data value will be rendered properly. So our example above would transform into:
First Item
Second Item
Third Item
I primarily use this technique for enabling HTML content in comment fields, and to insert line breaks when building the data for these fields.
Hope this helps out!
-Bob