Click here to Skip to main content
15,892,737 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi Friends,,


How to display an image in gridview from database which is in Binary format..?

i am using MySql database
Posted
Updated 27-Jan-13 21:49pm
v2

You have to use generic handler.
Refer - Showing image in GridView from the database?[^].

So, in DataBound event of Gridview you can write something like below.
C#
Image1.ImageUrl = "~/ShowImage.ashx?id=" + id;

Where Image1 is the image control in the gridview and id is the Foreign Key value like "Employee ID" in Image Table (you can get this while databinding).

The handler will return you the whole image and will be shown in that image control directly.

More reference :
1. Save and retrive Binarydata from database into image[^].
2. how to display image from sql table in gridview?[^]
 
Share this answer
 
v2
// Suppose you have image in grid like this

<img id="Img_1" src="GetImage.aspx" />

// create a new page "GetImage.aspx" and write the following code :

// load image binary from database like this :

byte[] bt = ((byte[])Ds.Tables[0].Rows[0]["dbimage"].ToString());
            
Response.Clear();
Response.ContentType = "image/x-icon";
Response.AddHeader("content-disposition", "inline;filename=image.jpg");
Response.Flush();
Response.BinaryWrite(bt);
Response.End();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900