How to display image from byte array

4 posts, 0 answers
  1. Paul
    Paul avatar
    15 posts
    Member since:
    Jan 2009

    Posted 09 Jul 2013 Link to this post

    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.
  2. Angel Petrov
    Admin
    Angel Petrov avatar
    1007 posts

    Posted 15 Jul 2013 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Yahya
    Yahya avatar
    2 posts
    Member since:
    Jul 2016

    Posted 18 Jul Link to this post

    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 
  5. Angel Petrov
    Admin
    Angel Petrov avatar
    1007 posts

    Posted 20 Jul Link to this post

    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.
Back to Top