Image is not displaying after adding items to cart

Shubham Riyal 1 Reputation point
2022-01-24T14:57:39.963+00:00

167909-screenshot-2.png

this error is showing in the console.

and the url is fine
<asp:Image ID="img" runat="server" ImageUrl=<%# Eval("ImageFile") %> />

protected void AllData()
{
if (Session["AddProduct"].ToString() == "true")
{
Session["AddProduct"] = "false";
DataTable dt = new DataTable();
DataRow dr;
dt.Columns.Add("S.No");
dt.Columns.Add("ImageID");
dt.Columns.Add("ImageName");
dt.Columns.Add("ImageFile");
dt.Columns.Add("Price");

            if (Request.QueryString["Id"] != null)  
            {  
                if (Session["Buyitems"] == null)  
                {  
                    dr = dt.NewRow();  
                    string cont = @"Data Source=abc;initial Catalog=New DataBase;integrated security=true;";  
                    SqlConnection sqlcon = new SqlConnection(cont);  
                    SqlCommand cmd = new SqlCommand();  
                    string query = "select * from tblclothes where ImageID=" + Request.QueryString["Id"];  
                    cmd.CommandText = query;  
                    cmd.Connection = sqlcon;  
                    SqlDataAdapter da = new SqlDataAdapter();  
                    da.SelectCommand = cmd;  
                    DataSet ds = new DataSet();  
                    da.Fill(ds);  
                    dr["S.No"] = 1;  
                    dr["ImageID"] = ds.Tables[0].Rows[0]["ImageID"].ToString();  
                    dr["ImageName"] = ds.Tables[0].Rows[0]["ImageName"].ToString();  
                    dr["ImageFile"] = ds.Tables[0].Rows[0]["ImageFile"].ToString();  
                    dr["Price"] = ds.Tables[0].Rows[0]["Price"].ToString();  

                    dt.Rows.Add(dr);  
                    gvproducts.DataSource = dt;  
                    gvproducts.DataBind();  
                    Session["buyitems"] = dt;  
                }  
                else  
                {  
                    dt = (DataTable)Session["buyitems"];  
                    int sr = dt.Rows.Count;  
                    dr = dt.NewRow();  
                    string cont = @"Data Source=SHUBHAMR_SDG\MSSQLSERVER01;initial Catalog=New DataBase;integrated security=true;";  
                    SqlConnection sqlcon = new SqlConnection(cont);  
                    SqlCommand cmd = new SqlCommand();  
                    string query = "select * from tblclothes where ImageID=" + Request.QueryString["Id"];  
                    cmd.CommandText = query;  
                    cmd.Connection = sqlcon;  
                    SqlDataAdapter da = new SqlDataAdapter();  
                    da.SelectCommand = cmd;  
                    DataSet ds = new DataSet();  
                    da.Fill(ds);  
                    dr["S.No"] = sr + 1;  
                    dr["ImageID"] = ds.Tables[0].Rows[0]["ImageID"].ToString();  
                    dr["ImageName"] = ds.Tables[0].Rows[0]["ImageName"].ToString();  
                    dr["ImageFile"] = ds.Tables[0].Rows[0]["ImageFile"].ToString();  
                    dr["Price"] = ds.Tables[0].Rows[0]["Price"].ToString();  

                    dt.Rows.Add(dr);  
                    gvproducts.DataSource = dt;  
                    gvproducts.DataBind();  
                    Session["buyitems"] = dt;  
                }  
            }  
        }  
        else  
        {  
            DataTable dt;  
            dt = (DataTable)Session["buyitems"];  
            gvproducts.DataSource = dt;  
            gvproducts.DataBind();  
        }  
    }  
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,253 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,237 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Yijing Sun-MSFT 7,066 Reputation points
    2022-01-25T05:29:01.43+00:00

    Hi @Shubham Riyal ,
    There are many reasons for 404. So, you need to do two things to check what's wrong with your codes:

    1. select "Network" in the console to check the details message of your errors.
    2. select "Sources" in the console and then check the <%# Eval("ImageFile") %> value.

    Best regards,
    Yijing Sun


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our  documentation  to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. P a u l 10,406 Reputation points
    2022-01-25T15:09:38.57+00:00

    Sorry if you mentioned somewhere in this post but just to clarify does the ImageFile in your tblclothes table contain a file name or the actual file data?