Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I please need help to get my image to display correctly in the tag that is created in a literal control.

        foreach (DataRow dr in dt.Rows)
        {
            string productName = dr["PRO_Name"].ToString();
            string productPrice = dr["PRO_Price"].ToString();
            byte[] productImg = (byte[])dr["PRO_Img"];

            string sProduct = @"<div class='four-shop columns isotope-item'>
                                 <div class='shop-item'>
                                  <figure>
                                  //I need the image from the data base here:
                                  <img src='" + productImg + "' alt='' />
                                  <figcaption center code herelass='item-description'>
                                  <h5>" + productName + "</h5>
                                  <span>R" + productPrice + "</span>
                                  <a href='#' class='button color'>Add to    Cart</a</figcaption>
                                  </figure>
                                  </div>
                                  </div>";
           //Im using a literal control to create the DIV dynamically for each product in the database.
           productPanel.Controls.Add(new LiteralControl(sProduct));
        }
share

1 Answer

You should put URL in your img tag and not a byte array as you do now:

<img src='" + productImg + "' alt='' />

Take a look at this answer about how to create an HTTP handler to retrieve the image using a URL: Display image from database in ASP.net with C#

share

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.