Batch Edit, File Upload

6 posts, 0 answers
  1. Mohammad
    Mohammad  avatar
    12 posts
    Member since:
    Dec 2014

    Posted 15 Apr 2015 Link to this post

    How can I use RadUpload or RadAsyncUpload control in RadGrid batch edit mode?

    I tried following code but RadAsyncUpload shows 0 files in UploadedFile enumerator.

     

    01.protected void RadGrid1_BatchEditCommand(object sender, GridBatchEditingEventArgs e)
    02.    {
    03.        foreach (GridBatchEditingCommand command in e.Commands)
    04.        {
    05.            if ((command.Type == GridBatchEditingCommandType.Update))
    06.            {
    07.                Hashtable newValues = command.NewValues;
    08. 
    09.                if (newValues != null)
    10.                {
    11.                    var CTRL = RadGrid1.FindControl(RadGrid1.MasterTableView.ClientID + "_AttachmentColumn");
    12.                    RadAsyncUpload asyncUpload = RadGrid1.FindControl(RadGrid1.MasterTableView.ClientID + "_AttachmentColumn").Controls[0] as RadAsyncUpload;
    13.                     
    14.                }
    15.            }
    16.        }
    17.    }

    <telerik:GridAttachmentColumn UploadControlType="RadUpload" EditFormHeaderTextFormat="Upload File:" HeaderText="Attachment Column" UniqueName="AttachmentColumn">
    </telerik:GridAttachmentColumn>

  2. Angel Petrov
    Admin
    Angel Petrov avatar
    1090 posts

    Posted 20 Apr 2015 Link to this post

    Hello,

    In order to extract the uploaded file contents you can modify the logic as demonstrated below.

    C#:
    protected void RadGrid1_BatchEditCommand(object sender, GridBatchEditingEventArgs e)
    {
        foreach (GridBatchEditingCommand command in e.Commands)
        {
            if ((command.Type == GridBatchEditingCommandType.Update))
            {
                Hashtable newValues = command.NewValues;
                if (newValues != null)
                {
                    byte[] file = (byte[])newValues["AttachmentColumn"];
                }
            }
        }
    }
    More information about accessing the user changes can be found in this help article.

    Regards,
    Angel Petrov
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  3. Mohammad
    Mohammad  avatar
    12 posts
    Member since:
    Dec 2014

    Posted 20 Apr 2015 in reply to Angel Petrov Link to this post

    How I will add column for above mentioned code?

    It will be without TemplateColumn of I have to use RadUpload or RadAsyncUpload control inside TemplateColumn?

  4. Angel Petrov
    Admin
    Angel Petrov avatar
    1090 posts

    Posted 23 Apr 2015 Link to this post

    Hi,

    I am experiencing difficulties understanding the query. Do you want to replace the GridAttachmentColumn with a GridTemplateColumn? If that is the case you may need to manually handle the editing process for the column. The idea here is to subscribe to the four batch editing events(OnBatchEditGetCellValue, OnBatchEditSetEditorValue, OnBatchEditGetEditorValue and OnBatchEditSetCellValue) and manually get set the cell/editor values. An example of such type of handling can be observed here.

    Regards,
    Angel Petrov
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  5. bosseman
    bosseman avatar
    6 posts
    Member since:
    Nov 2006

    Posted 21 Nov 2016 in reply to Angel Petrov Link to this post

    Greetings, I can retrieve the byte array from the newValues hashtable after using the RadAsyncUpload control in a batch edit mode data grid. How can I retrieve the actual name of the file in addition to the contents? 

    Thank you.

    Jim

  6. Angel Petrov
    Admin
    Angel Petrov avatar
    1090 posts

    Posted 24 Nov 2016 Link to this post

    Hello Jim,

    I am sorry to say but there isn't an exposed way to obtain the file name. You can however obtain a reference to the file upload control and its UploadedFiles collection. From there you may need to access the input stream of each file and compare it with the provided data.

    C#:
    foreach (GridBatchEditingCommand command in e.Commands)
            {
                if ((command.Type == GridBatchEditingCommandType.Update))
                {
                    Hashtable newValues = command.NewValues;
                    if (newValues != null)
                    {
                        byte[] file = (byte[])newValues["AttachmentColumn"];
     
                        // access the uploaded files
                        ((RadGrid1.FindControl(RadGrid1.MasterTableView.ClientID + "_AttachmentColumn").Controls[0] as RadAsyncUpload)).UploadedFiles
                    }
                }
            }


    Regards,
    Angel Petrov
    Telerik by Progress
    Telerik UI for ASP.NET AJAX is ready for Visual Studio 2017 RC! Learn more.
Back to Top