将图像添加到数据表和gridview

时间:2018-06-23 01:06:23

标签: asp.net vb.net gridview datatable webforms

尝试将jpg图片添加到数据表dtsun。 我该怎么做?

    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()

1 个答案:

答案 0 :(得分:0)

您可以直接在网格视图中添加图像列。.因此,您无需在dt中添加图像列。可以这样做

    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