Friday 25 May 2007

ASP.NET - Gridview HTMLEncode

Ever been frustrated that when you Auto generate columns, you cannot set the HTMLEncode property to false so that it renders HTML inside the Gridview?

Simple place the code inside the Gridviews RowDataBound event:



If (e.Row.RowType = DataControlRowType.DataRow) Then

Dim cells As TableCellCollection
cells = e.Row.Cells
Dim cell = New TableCell

For Each cell In cells
cell.Text = Server.HtmlDecode(cell.Text)
Next

End If



Now every cell that has HTML inside will get rendered, such as HREF's etc ;)

1 comment:

Sharif said...

That's awsome!
Thanks... always hated creating bound columns just to render html.

-shareefer20