Click here to Skip to main content
12,755,827 members (39,449 online)
Rate this:
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 22:46pm
Updated 27-Jan-13 22:49pm
Rate this: bad
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?[^]
Rate this: bad
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.ContentType = "image/x-icon";
Response.AddHeader("content-disposition", "inline;filename=image.jpg");


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

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170217.1 | Last Updated 28 Jan 2013
Copyright © CodeProject, 1999-2017
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