MyAcc.RunProcForDataReader("Pro_StudentInf_Search", parameters, out Myread);                         
                if (Myread.Read())
                {
                    string dirPath =Server.UrlEncode(HttpContext.Current.Server.MapPath("~/StuPic"));                  
                    string filename = Myread["Num"].ToString();
                    Image1.ImageUrl =Server.UrlDecode(dirPath) +"\\"+ filename + ".jpg";    
                            
                }           出来的路径为:src="F:\vs2005\VS2005%e9%a1%b9%e7%9b%ae\StuPic\271632588282.jpg" 
为什么始终image控件中是个红叉叉呀,郁闷死我了,哪位大哥帮忙呀。

解决方案 »

  1.   

    string dirPath =Server.UrlEncode(HttpContext.Current.Server.MapPath("~/StuPic"));  
    为什么要转成硬盘的里的真实路径呢??
      

  2.   

    我改成这样:
      Image1.ImageUrl = "~/StuPic"+"\\" + filename + ".jpg";     
      路径结果为:
      http://localhost:1886/VS2005%e9%a1%b9%e7%9b%ae/StuPic/271632588282.jpg
      但还是红叉叉
      

  3.   

    可以把图片的地址存放到数据库,然后查询存放地址的字段把它绑定到Image控件上去..也可以这样去绑定:<asp:Image ID="Image1" runat="server" Height="100px" Style="left: 15px; position: relative;
                                    top: 0px" Width="150px" [color=#FF0000]ImageUrl='<%# Eval("pgimgesurl") %>
    ' />[/color]
      

  4.   

    上面的有错误
    应该是:<asp:Image ID="Image1" runat="server" Height="100px" Style="left: 15px; position: relative;
                                    top: 0px" Width="150px" ImageUrl='<%# Eval("pgimgesurl") %>' />
      

  5.   

    通过HttpUtility.UrlEncode和UelDecode解码看看,一般用英文命名文件夹名称
    Image1.ImageUrl='<%# Eval("")%>'