views:

186

answers:

1

i have got a datatable in witch i have got image url. i dont want to create a tamplet column. i just want to assign my datatable as datasource of gridview and it should show image in its field like:

dim dt as new datatable
dr = dt.NewRow
dr("HotelName") = "citypalace"
dr("image") ="<img src='" &  "www.mycity.com/aa.jpg" & "'/>"   'but this is not working its showing url in that column... 
dt.rows.add(dr)
gridview1.datasource = dt
gridview1.databind()

please give me solution that what should i do with that column of datatable so it will show image in gridview. (please dont say me to create a template column).

+1  A: 

The GridView control automatically html-encodes everything, but there are a couple ways you can turn it off. If you have the image field declared in the aspx page, the easiest option is to just set the HtmlEncode property to false.

<asp:BoundField DataField="image" HtmlEncode="false" />

If this isn't feasible in your case, you can 'undo' the html encoding for these cells on the GridView's RowDataBound event.

Private Sub gridview1_RowDataBound(ByVal sender As Object, ByVal e As   System.Web.UI.WebControls.GridViewRowEventArgs) Handles gridview1.RowDataBound
    e.Row.Cells(1).Text = Server.HtmlDecode(e.Row.Cells(1).Text)
End Sub

I'm assuming from your example that your GridView has 2 columns and the image column is the second one, hence Cells(1) in each row. Hope this helps!

Kurt Schindler