Click here to Skip to main content
Sign Up to vote bad
good
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:46
Edited 27 Jan '13 - 21:49


2 solutions

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  
// 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
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 399
1 Mahesh Bailwal 353
2 Maciej Los 270
3 CPallini 245
4 Rohan Leuva 175
0 Sergey Alexandrovich Kryukov 9,162
1 OriginalGriff 7,194
2 CPallini 3,923
3 Rohan Leuva 3,176
4 Maciej Los 2,633


Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 28 Jan 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid