0

I save image in database then want to load and show image in image control. I load data from database.control image is:

<asp:Image ID="imgShow" runat="server" />

code to show image:

imgShow=listUser[0].File;   // File is byte[]

listUser[0].File is byte[] .how can show image?

shahroz
  • 359
  • 1
  • 6
  • 17
  • 2
    Possible duplicate of [Retrieve image from database into a image tag](http://stackoverflow.com/questions/18731712/retrieve-image-from-database-into-a-image-tag) – haraman Oct 27 '15 at 09:15

2 Answers2

0
 <asp:TemplateField>
        <HeaderTemplate>Image</HeaderTemplate>
        <ItemTemplate>
            <img src='data:image/jpg;base64,<%# Eval("yourimagebytefield") != System.DBNull.Value ? Convert.ToBase64String((byte[])Eval("yourimagebytefield")) : string.Empty %>' alt="image" height="100" width="200"/>
        </ItemTemplate>
    </asp:TemplateField>
Kaushik Maheta
  • 1,741
  • 1
  • 18
  • 27
0

I believe you have already got your answer. I would just like to add that its never a good idea to store image directly in the database, its not an efficient method. What you should do instead is to store the image in a directory and then store the location of that image in the database.Its going to be much more efficient.

musab shaheed
  • 150
  • 1
  • 7
  • thanks for answer.image is secure and we cant save in directory sines customer dont like do it. – shahroz Oct 28 '15 at 05:07