Click here to Skip to main content
11,715,491 members (85,420 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
Hi Friends,,


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

i am using MySql database
Posted 27-Jan-13 21:46pm
Edited 27-Jan-13 21:49pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
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?[^]
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

// 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();
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 518
1 Richard MacCutchan 300
2 Maciej Los 259
3 ManasKumarM 155
4 Frankie-C 125
0 Sergey Alexandrovich Kryukov 785
1 CHill60 415
2 Richard MacCutchan 405
3 Maciej Los 389
4 OriginalGriff 320


Advertise | Privacy | Mobile
Web01 | 2.8.150901.1 | Last Updated 28 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100