Friday, October 23, 2009

Okay, maybe this is no revelation for some of you out there, but here’s a quick, down-and-dirty way of displaying an HTML-Encoded column in a GridView. By default, the GridView will display bound columns with the HTML encoding so if you want to see the HTML formatting you need to do an HTMLDecode operation.

In the GridView.RowDataBound() event add the following line of code…

e.Row.Cells(4).Text = Server.HtmlDecode(e.Row.Cells(4).Text)

Substitute the number (in this case 4) with the column that contains the HTML, unless of course the column IS 4! You could also do an HTMLDecode on each column using the following syntax.

For Each oCell As TableCell in e.Row.Cells

oCell.Text = Server.HtmlDecode(oCell.Text)

Next

You are better off however if you simply decode the required columns because of performance. Not every column in your GridView is likely to contain HTML.

That’s all folks!!

 

Friday, October 23, 2009 10:44:29 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0]
Comments are closed.