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
  • 453
  • 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,236
  • 13
  • 56
  • 110