C# – using repeater control to display an image from database C#

asp.netc

I have a book database(2 books in total right now) where for each book i have a row called 'Image' that contains the name of the images.
For example. cprog.jpeg and asm.jpeg

Using the repeater i can display the book information like name, author, etc. But i dont know how to get the images to display. The images are stored in the images folder.

here is the aspx which is the issue? since, it displays the bookname and description just fine.

<asp:Repeater ID="Repeater1" runat="server">
        <ItemTemplate>
 <%# DataBinder.Eval(Container.DataItem, "BookName") %>
 <hr>
 <%# DataBinder.Eval(Container.DataItem, "BookDescription") %>
 <td width="100px">
  <p align="left">


 <img src= '<%# DataBinder.Eval(Container.DataItem, "Image") %>.jpeg'  
 alt="" style="height:200px;width:200px;border:1px solid gray;"/>

  </td>
  </p>

Code behind

String connectionString = "Data Source=" + Server.MapPath(@"~\App_Data\bookDB.db");
        String selectCommand = String.Format("Select * from Book where CategoryName = '{0}'", Request.QueryString);
        SQLiteConnection myConnection = new SQLiteConnection();
        myConnection.ConnectionString = connectionString;
        myConnection.Open();
        SQLiteDataAdapter dataAdapter = new SQLiteDataAdapter(selectCommand, myConnection);

        myConnection.Close();
        // DataSet ds = new DataSet();
        dataAdapter.Fill(ds2);


        DataTable table = new DataTable();
        dataAdapter.Fill(table);
        Repeater1.DataSource = table;
        Repeater1.DataBind();

Once, when i ran the project the broken image appeared for a second and then disappeared. I have spent the last 2 days trying to get this with no avail…
Thank you.

Best Answer

Assuming the images folder is /images, adding the folder name and deleting the extension (already in database as mentioned in your question) should display the image:

<img src='/images/<%# DataBinder.Eval(Container.DataItem, "Image") %>'  
alt="" style="height:200px;width:200px;border:1px solid gray;"/>

If that doesn't yield the desired result, check the html output and compare it to the real url - what's different?