在GridView中,我添加了一个GridView自带的ImageField控件,也已经把它的DataImageUrlField绑定在ImageUrl字段上,但就是显示不出图片的内容,我在HTML中测试过,ImageUrl的图片路径是正确的,可以显示出图片。后来我把该字段转化为模板字段,用Image控件来绑定,也还是显示不出图片来。我测试了一天,没查出错在哪?

解决方案 »

  1.   

    Image控件定位方式有问题吧,去掉css属性试试
      

  2.   

    你用的是相对路径吗?用的是images/1.gif还是~/images/1.gif
      

  3.   

    我就贴一段相关的吧:这段是确定Upload控件的路径:
    HttpPostedFile postFile = this.smallphoto.PostedFile;
                    string smallname = smallphoto.FileName.ToString();
                    string type1 = smallphoto.PostedFile.ContentType.ToString();
                    string type2 = smallname.Substring(smallname.LastIndexOf(".") + 1);
                    string strFileName = smallname;
                    string size = smallphoto.PostedFile.ContentLength.ToString();
                    string timefile = DateTime.Now.ToString("yyMMddHHmmss");
                    string smallSavePath = Server.MapPath("~\\Products\\" + timefile + "small" + smallname);然后,在ImageField控件中的DataImageUrlField属性中绑定ImageUrl字段,其字段正是储存上述程序中变量smallSavePath中的值。
    我在数据库里把其值粘贴在Html 里面的<img>里面的src中,发现能正确显示图片,没任何问题。这是为什么呢?
      

  4.   

    Server.MapPath("~\\Products\\" + timefile + "small" + smallname); 你明白Server.MapPath是干嘛用地吗??嘿嘿,著名的csdn “硬盘图" 问题
      

  5.   

    你是要把上传后的图片显示到GridView里是吗??
      

  6.   

    image控件中,你把路径写成 "~/image/xxx.jpg"
    ~/是根目录..这样就不会错了.
      

  7.   

    加了Server.MapPath
    就不要在路径前面加~