简体   繁体   English

手动将图像URL添加到gridview中的图像列

[英]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. 我正在一个项目中,我必须在DataTable搜索一些值并查看带有添加图像列的结果,图像URL存储在另一个表中。

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. 到目前为止,我已经能够将图像类型列添加到GridView中,但是我正在努力将图像URL分配到这些图像列单元格中。

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? 是否可以通过查询将图像URL馈入此新添加的列中?

Like this: 像这样:

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

You want to show Image in a GridView ? 您想在GridView中显示Image吗?

if yes, then add a template column in a gridview and bind image path to it. 如果是,则在gridview中添加一个模板列,并将图像路径绑定到它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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