在文件夹中的网格中显示图像 [英] Displaying image in a grid from a folder

查看:100
本文介绍了在文件夹中的网格中显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经写了这样的代码....

I have written the code like this....

DataTable dt = new DataTable();
dt.Columns.Add("Image", typeof(string));
DataRow dr;
int i = 1;
foreach (string file in Directory.GetFiles(Server.MapPath(@"ImageUpload\")))
{
  //string nm = Path.GetFileName(file);
  dr = dt.NewRow();
  dr[0] = ResolveUrl(file);
  dt.Rows.Add(dr);
  i += 1;
}
grdimage.DataSource = dt;
grdimage.DataBind();



在这里,我的问题是图像没有显示在网格视图中.有人可以帮我吗?



Here, my problem is, that the image is not displayed in grid view. Can anyone please help me out?

推荐答案

只是因为您有图像路径并不意味着它将自动显示图像,所以您需要做一些工作.

您有一个包含Image控件的模板列,并将src属性从DataTable中绑定到Image列
Just because you have an image path doesn''t mean it will automatically display the image, you need to do a little work.

You have a template column that includes an Image control and you bind the src property to the Image column from your DataTable


选中此选项.


check this.


DataTable dt = new DataTable();
        dt.Columns.Add(new DataColumn("Image", typeof(string)));
        DataRow dr;
        int i = 0;
        foreach (string file in Directory.GetFiles(Server.MapPath(@"ImageUpload\")))
        {
            dr = dt.NewRow();
            dt.Rows.Add(dr);
            dr["Image"] = "ImageUpload/" + System.IO.Path.GetFileName(file);
            i += 1;
        }
        GridView1.DataSource = dt;
        GridView1.DataBind();











<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
      <Columns>
          <asp:ImageField  DataImageUrlField="Image">
          </asp:ImageField>
      </Columns>
  </asp:GridView>


看看 [ ^ ]或 ^ ]文章,加入 [ ^ ]线程.

我想您可能会摆脱所有疑问.

如果有帮助,请 投票 接受答案 .
Take a look at THIS[^] or THIS[^] Article ,Join THIS[^] thread.

I think you might get out of all your doubts.

Please vote and Accept Answer if it Helped.


这篇关于在文件夹中的网格中显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆