如何在GridView中显示图像 [英] How to display the image in a gridview

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

问题描述

我有一个不显示该图像的图像.我已将图像存储在名为"UserImages"的文件夹中
设计代码:该代码位于GridView内部

i have an image that does not display the image. i have stored the image in a folder called "UserImages"
Design Code : The code is inside the GridView

<asp:Image ID="ImageLogo" runat="server" Width="75" Height="80" Text='<%#Eval("User_Image") %>' ToolTip='<%#Eval("User_Image") %>' />



背后的代码



Code Behind

protected void DataList1_RowDataBound(object sender, GridViewRowEventArgs e)
       {
           if (e.Row.RowType == DataControlRowType.DataRow)
           {
      (e.Row.FindControl("ImageLogo") as Image).ImageUrl = "/UserImages/" + e.Row;

           }
       }

推荐答案

您的图片路径是错误的,就像〜/UserImages/" + er = Row;
your image path is wrong it is like that "~/UserImages/" +e.r=Row;


像这样的图片上传代码..


Image upload code like this..


<asp:gridview id="GridView1" runat="server" autogeneratecolumns="False" xmlns:asp="#unknown">
            Height="16px" Width="100px">
        <columns>
        <asp:imagefield headertext="Profile Picture" dataimageurlfield="Path" />
        </columns>
        </asp:gridview>









public void fill()
        {
            string name = Application["Name"].ToString();
            SqlDataAdapter da = new SqlDataAdapter("select Path from tbl_imageupload where UserName ='" + name + "'", con);
            DataTable dt1 = new DataTable();
            da.Fill(dt1);
            GridView1.DataSource = dt1;
            GridView1.DataBind();
        }


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

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