且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在网格视图中显示图像

更新时间:2023-01-24 11:48:25

for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{

   int itemid = Convert.ToInt32(ds.Tables[0].Rows[i][3]);
   img.ImageUrl = "~/Handler1.ashx?id=" + itemid;
   img.DataBind();
}



原因是您要遍历数据集中的所有行,然后每次将imageUrl设置为最后一行.您真正要问自己的是,如果一行上只有1张图片,为什么要使用循环?



The reason is that you are looping through all the rows in a the dataset, and then setting the imageUrl to the last one every time. What you really need to ask yourself is Why are you using a loop if you only have 1 image on the row?