Geeks With Blogs
Bob Palmer's Developer Blog .NET, SQL, and Silverlight Development

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
 

Posted on Sunday, March 7, 2010 1:29 PM | Back to top


Comments on this post: C# Tip - Rendering HTML in a Gridview cell

# re: C# Tip - Rendering HTML in a Gridview cell
Requesting Gravatar...
Sounds great, but what can you do in cases where the Gridview is being populated (columns and all) dynamically?
Left by Josh on Jan 06, 2011 2:04 PM

# re: C# Tip - Rendering HTML in a Gridview cell
Requesting Gravatar...
good idea thank you
Left by Jubpas on Nov 21, 2011 10:03 PM

# re: C# Tip - Rendering HTML in a Gridview cell
Requesting Gravatar...
Best tip I have seen in the whole year!
Left by Miguel on Dec 04, 2013 1:38 PM

Your comment:
 (will show your gravatar)


Copyright © BobPalmer | Powered by: GeeksWithBlogs.net