How to Display Images automatically in my GridImageColumn from my images folder?

2 posts, 0 answers
  1. Cece
    Cece avatar
    2 posts
    Member since:
    Jun 2019

    Posted 07 Jun Link to this post

         I'm trying to display images on my gridimagecolumn without me having to upload it myself but instead it does it automatically when i load the grid. How do I do that? 

     

    My template is => 

     <telerik:GridBinaryImageColumn  DataField="Profile" HeaderText="Profile" UniqueName="Upload" ImageHeight="60px" ImageWidth="60px" ResizeMode="Fit"></telerik:GridBinaryImageColumn>   

     

    I haven't yet figure the code out on how to go about this...This is what I have so far.

    protected void uxUsedGrid_InsertCommand(object source, GridCommandEventArgs e)
            {
                _InsertCommand(source, e);
            }
     
            private void _InsertCommand(object source, GridCommandEventArgs e)
            {
     
                GridEditFormInsertItem insertItem = e.Item as GridEditFormInsertItem;
                RadAsyncUpload radAsyncUpload = insertItem["Upload"].FindControl("AsyncUpload1") as RadAsyncUpload;
     
                UploadedFile file = radAsyncUpload.UploadedFiles[0];
                byte[] fileData = new byte[file.InputStream.Length];
                file.InputStream.Read(fileData, 0, (int)file.InputStream.Length);
     
                
            }
     
    protected void AsyncUpload1_FileUploaded(object sender, FileUploadedEventArgs e)
            {
                long totalBytes = 0;
                int MaxTotalBytes = 1000000;
                if ((totalBytes < MaxTotalBytes) && (e.File.ContentLength < MaxTotalBytes))
                {
                    e.IsValid = true;
                    totalBytes += e.File.ContentLength;
                    IsRadAsyncValid = true;
                }
                else
                {
                    e.IsValid = false;
                    IsRadAsyncValid = false;
                }
            }

     

    I have look at this Demo and while it was helpful, it mostly focused on the client uploading the files and basing it off from that to upload the images. 

    Any help is appreciated!

  2. Eyup
    Admin
    Eyup avatar
    3867 posts

    Posted 12 Jun Link to this post

    Hi Cece,

    The GridImageColumn is suitable for images coming from a database field. For other scenarios, you can try using an ItemTemplate and display the image the same way you would have displayed it on a regular aspx page:
    https://docs.telerik.com/devtools/aspnet-ajax/controls/grid/columns/column-types#gridtemplatecolumn

    I hope this will prove helpful.

    Regards,
    Eyup
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top