2

I have a linq datasource to a repeater control in asp.net.
I want to display images stored in the database tables.

i have a category table and product table among other tables, when i used this code

<% Eval("CategoryImage")%> .

It displays System.byte[] in the browser and when I used asp image control with Eval(); it give me a usual broken image icon.

could somebody suggest me a way to insert image directly from the mysql database itself via linq datasource..
And how could I format html tags in stack overflow and asp tags too..

Thanks in advance help appreciated...

Vishal Torne
  • 319
  • 3
  • 23

1 Answers1

3

You can use this function

 public Image byteArrayToImage(byte[] byteArrayIn)
 {
    MemoryStream ms = new MemoryStream(byteArrayIn);
    Image returnImage = Image.FromStream(ms);
    return returnImage;
 }

to convert the byte array to image.

And if you have byte array in Eval("CategoryImage") then you can call this function from Eval also.
As

<%# byteArrayToImage(Eval("CategoryImage"))%>

Not tested but it should work.

Edit 1

Here is a good link
argumentException was unhandled error when converting byte of array to image
How to convert byte array to image and display in datagrid?

Community
  • 1
  • 1
शेखर
  • 17,236
  • 13
  • 56
  • 110