0

There is no error showing up in the c# code but the created web design doesn't show the image. *stored the path of image in a column in the database using SQL server management studio. *Connected the database to my project where there is a grid view containing image control. *The folder in which the images are stored is in the project folder itself.

*I have already tried changing different paths, adding some height and weight properties to the image control.

Logo is the name of the column in the database where the path of the images where given. enter image description here

Retrieves everything from the database except for the image enter image description here

I want the images to be displayed after running my .aspx page.

demo
  • 6,038
  • 19
  • 75
  • 149
  • 2
    Post your code where you're retrieving Logo from the database. What happens when you put that URL of the image directly into the browser, does it get a 404? – Jon Apr 23 '19 at 14:37
  • Did you set the "Copy to Output Directory" to something other than "Do not copy" in the file properties in Solution Explorer. – Mark Rabjohn Apr 23 '19 at 14:39
  • It's impossible to answer this question. Is `Logo` a path or image data? The `ImageUrl` attribute suggests it's an URL. If the values loaded from the database point to non-existent images, you'll get a broken image. If `Logo` is a relative path that ends up pointing to the wrong location, you'll get a broken image. – Panagiotis Kanavos Apr 23 '19 at 14:39
  • Did you check what the generated URLs point to? Are the URLs valid? Are the images there? – Panagiotis Kanavos Apr 23 '19 at 14:41
  • You URL for image is wrong. See following : https://stackoverflow.com/questions/46536653/convert-bytes-to-image-asp-net-c-sharp-and-use-it-in-image1-url Should look like this : this.Image1.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(ms.ToArray()); – jdweng Apr 23 '19 at 14:48
  • Logo is not a path or image data. It is the name of the column where the path of the images is written as PIC/image.jpg in each row respectively. PIC is the folder i created in the visual studio - solution explorer which contains the images. – kalyan prasad Apr 23 '19 at 14:49
  • 1
    what data you are storing in Logo column in database? – Kevin Shah Apr 23 '19 at 14:54
  • 1
    You can see the result of your call In your browser developer tools/network. It is most probably a 404. Here's how to do it on Chrome: https://developers.google.com/web/tools/chrome-devtools/network/ FireFox: https://developer.mozilla.org/en-US/docs/Tools/Network_Monitor/request_details – Faheem Apr 23 '19 at 14:59
  • "Logo is not a path or image data. It is the name of the column" ....we realise that, obviously. You are being asked about the _content_ of that column. If those contents do not form a valid URL (or at least a relative URL) to an imagine file on your server then you'll get the result shown. As Achilles says, you can check what URLs are actually being called by monitoring your Network while the page is loading, or by inspecting the HTML code (use the "View Source" feature in your browser, or the element inspector) to see what the generated `` tags looks like. – ADyson Apr 23 '19 at 15:31
  • We can't tell you what you did wrong with the URLs because we don't know a) what the URLs look like, or b) what images are stored in your folder, or whether they have been properly deployed with your project when executing it. – ADyson Apr 23 '19 at 15:35

1 Answers1

0
  ----AdminPage.aspx-------------
     <ItemTemplate>
     <asp:Image ID="Image1" ImageUrl="" runat="server" Width="50" Height="50"/>
      </ItemTemplate>


      ----AdminPage.aspx.cs-------------

       protected void Page_Load(object sender, EventArgs e)
    {
        string str = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
       SqlConnection con = new SqlConnection(str);
       con.Open();
        SqlCommand cmd = new SqlCommand("select Logo from TableName", con);
        cmd.CommandType = CommandType.Text;
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
        con.Close();
        if (ds.Tables[0].Rows.Count > 0)
        {
            Image1.ImageUrl = "../PIC/" + ds.Tables[0].Rows[0]["Logo"].ToString();

        }
    }
Ravi Sharma
  • 362
  • 1
  • 5