开发者

Cannot display image

I had Image control and I added code to display images But there is not any i开发者_运维知识库mage displayed

ASPX:

<body>
    <form id="form1" runat="server">
    <div dir='<%= sDirection %>'>
        <div  id="ContentImage" runat="server">
            <asp:Image ID="Image2" runat="server" />
        </div>
    </div>

    </form>
</body>

C#:

using (System.Data.SqlClient.SqlConnection con = Connection.GetConnection())
        {
            string Sql = "Select Image From AboutUsData Where Id=@Id";
            System.Data.SqlClient.SqlCommand com = new System.Data.SqlClient.SqlCommand(Sql, con);
            com.CommandType = System.Data.CommandType.Text;
            com.Parameters.Add(Parameter.NewInt("@Id", Request.QueryString["Id"].ToString()));
            System.Data.SqlClient.SqlDataReader dr = com.ExecuteReader();
            if (dr.Read() && dr != null)
            {



                Image2.ImageUrl = dr["Image"].ToString();

            }
        }


Is there any exception thrown when running DB command? Does dr["Image"] contain some value? What about CSS, ContentImage maybe hiding div container?


Looking at your code it seems you're setting the ImageUrl property for Image1 instead of Image2.

Also, you have to make sure that the ImageUrl path returned actually maps to an image on the server (wether relative or absolute). To put an example, if your code renders this image:

<img src="images/photo.gif" alt="my photo2" />

but there is no image in images/photo.gif, because its actually located in ../images/photo.gif (the images directory sits elsewhere) then no image will be displayed by the browser.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜