How to create a Template Column with an Image in a datagrid?

S

Shapper

Hello,

How to create a Template Column with an Image in a datagrid from my VB
code?

Thanks,
Miguel
 
G

Guest

Hi,
First you need to create a TemplateColumn and add it to the datagrid.
Dim tmpCol As TemplateColumn
tmpCol = New TemplateColumn
DataGrid1.Columns.Add(tmpCol)

Then on the DataGrids itemBound event you have to add an image to the cell.
Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid1.ItemDataBound
Dim imgTemp As New System.Web.UI.HtmlControls.HtmlImage
imgTemp.Src = "..."(Path of the image)
e.Item.Cells(0).Controls.Add(imgTemp)
End Sub
PS:I have given a simplest way of getting an image column in a datagrid.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top