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
  • 366
  • 5
  • 24

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,412
  • 13
  • 61
  • 117
  • @ub1k dude do you have a train to catch.. i will accept it but let me work on it. – Vishal Torne Mar 02 '13 at 18:42
  • @Shekhar i am not getting an byte array but just System.Byte[] as output in the browser on using <% Eval("CategoryImage")%>.. could you help me with this.. – Vishal Torne Mar 02 '13 at 19:00
  • Dude from you're answer it's obvious you don't know what you're talking about :( Byte[] is a Byte array... – ub1k Mar 02 '13 at 19:10
  • @ub1k please do you know any suggestion to the question then please let me know ..or don't take my I.Q test.. i know i m not a great scholar as you are.. – Vishal Torne Mar 02 '13 at 19:19
  • it's just the answer is provided by Shekhar! – ub1k Mar 03 '13 at 06:56
  • yeah but it is giving me an error : that ByteArrayToImage(Byte[]) has some invalid Arguments on <%#byteArrayToImage(Eval("CategoryImage")) %> – Vishal Torne Mar 03 '13 at 14:37