Ynk 1993
Ynk 1993

Reputation: 69

Insert images from mysql database into C# datagrid view

I have a database which contains many columns, one of the columns is an image column , this contains the image of a particular person in raw format. I want to put this image on datagrid view in C# . I am able to show all other data except the image.

Upvotes: 0

Views: 223

Answers (2)

Ehsan Sajjad
Ehsan Sajjad

Reputation: 62488

You can use handler to display image in gridview , your html markup look like inside

Gridview ItemTemplate set image control src as src=~/ShowImage.ashx?id=" + id

where ShowImage.ashx is your handler which return MemoryStream((byte[])img);

Here is a similar article how to get binary data and display as image

https://codepedia.info/convert-binary-data-to-image-save-and-retrieve-image-from-binary-data-asp-net-c/

In your case your querystring is characterID

so your image src would be src=~/ShowImage.ashx?id=" + characterID

Upvotes: 1

Ynk 1993
Ynk 1993

Reputation: 69

OKay got it . you do the normal updating of datagrid view with ur query and then make sure u set your datagrid view columns and rows to autosize so that u can see ur images

Upvotes: 0

Related Questions