简体   繁体   中英

how to bind image from database in asp.net using c#?

I have an image in a table(byte format). I want to bind this image (byte format) to an image button.I search the record and I have to display this image to this image button.Someone please help me out.Any help I would be grateful to you..

Suppose that you have data in imageData byte array

byte[] imageData=...;

You need to convert it into base64 as follows

string imageBase64 = Convert.ToBase64String(imageData);
string imageSrc = string.Format("data:image/gif;base64,{0}", imageBase64);

An in your page you can use

<img src= "<%= ImageSrcBytes %>" />

Note that it will not work in lower end browser.

For those browsers you need to save image in local folder and then provide the url for that image.

Or you can create a handler and call that handler as image source.

Some useful links

  1. Displaying Database Images in Gridview with HttpHandler

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM