0

Trying to add a jpg image to the datatable dtsun. How do I do this?

    Dim dtsun As New DataTable()
    dtsun.Columns.Add("col1")
    dtsun.Columns.Add("col2")
    dtsun.Columns.Add("col3")
    dtsun.Rows.Add(ImageUrl("~/jpg/" & col1name & ".jpg"), ImageUrl("~/jpg/" & col2name & ".jpg"), ImageUrl("~/jpg/" & col3name & ".jpg"))

    GridView1.DataSource = dtsun
    GridView1.DataBind()
jmcilhinney
  • 50,448
  • 5
  • 26
  • 46
  • Possible duplicate of [add image to datatable or gridview](https://stackoverflow.com/questions/17701661/add-image-to-datatable-or-gridview) – ArunPratap Jun 23 '18 at 05:18

1 Answers1

0

You can add directly a image column to grid view.. so you don't need to add an image column to dt. This can be done like this

    GridName.Columns.Clear()
    Dim ds As DataSet = SqlHelper.ExecuteDataset(connect(), CommandType.StoredProcedure, ProcedureName, Parameter)
    Dim DT As DataTable = ds.Tables(0)
    GridName.DataSource = DT
    Dim img As New DataGridViewImageColumn()
    Dim inImg As System.Drawing.Image = My.Resources.edit
    img.Image = inImg
    img.HeaderText = "Edit"
    img.ToolTipText = "Edit"
    GridName.Columns.Add(img)
    img.DefaultCellStyle.BackColor = System.Drawing.Color.MediumAquamarine