This is a migrated thread and some comments may be shown as answers.

How to display image from byte array

3 Answers 857 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 10 Jul 2013, 04:18 AM
After multiple files are uploaded from AsyncUpload, I loaded all of those images to byte array so that they can be displayed in the grid. I don't want to save these images  yet since I only want to save these images when the user clicks on Save.

How do I load those images in byte array into GridImageColumn?

It seems that there is no way to directly reference to temporarily file that is created from AsyncUpload. If it can, that will help.

3 Answers, 1 is accepted

Sort by
0
Angel Petrov
Telerik team
answered on 15 Jul 2013, 02:02 PM
Hi Paul,

Since you have a byte array that contains the image you can use a GridBinaryImageColumn and assign the byte array to the RadBinaryImage in the column. A demonstration of this can be observed in the code snippet below:

ASPX:
<Columns>
                    <telerik:GridBinaryImageColumn UniqueName="BinaryImageColumn"></telerik:GridBinaryImageColumn>
                </Columns>

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
   {
       GridDataItem item = e.Item as GridDataItem;
       if(item!=null)
       {
           (item["BinaryImageColumn"].Controls[0] as RadBinaryImage).DataValue=The byte array;
       }
   }

As for referencing the file which is uploaded this can be done by subscribing to the OnFileUploaded event like explained in this help article.

Regards,
Angel Petrov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
0
Yahya
Top achievements
Rank 1
answered on 18 Jul 2016, 10:05 AM
I followed the steps you provided however it says "The name "img" does not exist in the current context", although I identified "img" as a byte[] and filled it with the required data 
I followed the steps you provided however it says "The name 'img' does not exist in the current context", although I identified img as a byte[] and filled it with the required data 
I followed the steps you provided however it says "The name 'img' does not exist in the current context", although I identified img as a byte[] and filled it with the required data 
I followed the steps you provided however it says "The name 'img' does not exist in the current context", although I identified img as a byte[] and filled it with the required data 
0
Angel Petrov
Telerik team
answered on 20 Jul 2016, 07:40 AM
Hi,

Could you please share with us the page code(markup and code-behind) so we could examine the implementation? That would greatly facilitate us in providing a precise answer.

Regards,
Angel Petrov
Telerik by Progress
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
Grid
Asked by
Paul
Top achievements
Rank 1
Answers by
Angel Petrov
Telerik team
Yahya
Top achievements
Rank 1
Share this question
or