简体   繁体   中英

Manually add image url to image column in gridview

I am working on a project where I have to search some values in the DataTable and view the results with added image column, the image URLs are stored in a different table.

So far I was able to add the image type column in to the GridView but I am struggling to give image URLs into those image column cells.

This is how I have added the image column:

DataTable dt = new DataTable();
dt.Columns.Add("Student ID");
dt.Columns.Add("Semester");
dt.Columns.Add("Year");
dt.Columns.Add("Assigment 01");
dt.Columns.Add("Assigment 02");
dt.Columns.Add("Exam");
con.Open();
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
    DataRow dr = dt.NewRow();
    dr["Student ID"] = rdr["StudentID"];
    dr["Semester"] = rdr["SemesterID"];
    dr["Year"] = rdr["Year"];
    dr["Assigment 01"] = rdr["Assigment_01"];
    dr["Assigment 02"] = rdr["Assigment_02"];
    dr["Exam"] = rdr["Exam"];
}
ImageField img = new ImageField();
img.HeaderText = "Image";
GridView1.Columns.Add(img);
GridView1.Visible = true;

Is there are way to feed image URLs into this newly add column from using a query?

Like this:

string ImagePaths = "Select Image from StudentData where StudentID="'+rdr["StudentID"]+'");

You want to show Image in a GridView ?

if yes, then add a template column in a gridview and bind image path to it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM