0

I have a collection which has items consisting of Id as Integer,Name as String and a IconImage as Byte().

I want to display Name and the image in a gridview but not sure how to bind IconImage to gridview?

<itemtemplate>
    <asp:label id="LabelName" runat="server" text='<%# Eval("Name")%>'></asp:label>
</itemtemplate>

<!-- Bind and Display the image here-->  

Please help me with some sample code..
Thanks

user1770609
  • 463
  • 1
  • 4
  • 12
  • I found another nice article on this topic: [here](http://www.codeproject.com/Tips/445876/Auto-bind-byte-to-asp-Image) – user1770609 Apr 02 '13 at 22:35

1 Answers1

0

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
  • I tried ` " width="125px" height="125px" title="<%# Eval("Description") %>" /> ` but can't see any images,only cross(x) in the columns, any ideas? – user1770609 Mar 26 '13 at 11:45
  • Do the `IconImage` is a byte array? – शेखर Mar 26 '13 at 13:41
  • yes it is a byte array, maybe I'm using the wrong control to bind it to, I'm not sure if src can directly display an image, maybe it's expecting a full path to a file – user1770609 Mar 27 '13 at 01:39