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

Access to RadAsyncUpload in GridTemplateColumn on OnBatchEditCommand event

1 Answer 131 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Alexandr
Top achievements
Rank 1
Alexandr asked on 23 Aug 2017, 01:24 PM

Hello,

 

I have a grid with row BatchEditMode and GridTemplateColumn with RadAsyncUpload in Edittemplate. I try to save file to fileserver on OnBatchEditCommand, but I can not access to RadAsyncUpload from code behind.

 

<telerik:RadGrid runat="server" Skin="Metro" RenderMode="Lightweight" ID="gvAuditorium" AutoGenerateColumns="False" DataSourceID="dsAuditorium"
    AllowAutomaticDeletes="false" AllowAutomaticInserts="False" AllowAutomaticUpdates="False" AllowPaging="True"
    OnBatchEditCommand="gvAuditorium_OnBatchEditCommand">
    <MasterTableView DataKeyNames="RoomId" PageSize="50" EditMode="Batch" CommandItemDisplay="TopAndBottom">
        <CommandItemSettings ShowAddNewRecordButton="False" ShowRefreshButton="False"></CommandItemSettings>
        <BatchEditingSettings EditType="Row" OpenEditingEvent="Click"></BatchEditingSettings>         
        <Columns>
            <telerik:GridBoundColumn DataField="Number" SortExpression="Number" UniqueName="Number" HeaderText="Номер аудитории" ReadOnly="True"></telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="RoomName" SortExpression="RoomName" UniqueName="RoomName" HeaderText="Название" ReadOnly="True"></telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="TypeRoomName" SortExpression="TypeRoomName" UniqueName="TypeRoomName" HeaderText="Тип аудитории" ReadOnly="True"></telerik:GridBoundColumn>
            <telerik:GridNumericColumn DataField="Square" SortExpression="Square" UniqueName="Square" DataFormatString="{0:N2}" DecimalDigits="2" HeaderText="Площадь" />
            <telerik:GridNumericColumn DataField="PlaceCount" SortExpression="PlaceCount" UniqueName="PlaceCount" DecimalDigits="0" DataFormatString="{0:0}" HeaderText="Количество мест"/>          
            <telerik:GridTemplateColumn DataField="ScanFileName" UniqueName="ScanFileName" HeaderText="План аудитории">
                <ItemTemplate>
                    <asp:HyperLink runat="server" ID="hlToFile" Target="_blank" Visible='<%# Eval("hasFile") %>' Text='<%# Bind("ScanFileName") %>' NavigateUrl='<%# "~/_layouts/15/FastAuditoriumFilling/AuditoriumFileDownload.aspx?RoomId=" + Eval("RoomId")  %>' ></asp:HyperLink>
                </ItemTemplate>
                <EditItemTemplate>
                    <telerik:RadAsyncUpload runat="server" ID="auFileUpload" Skin="Metro" RenderMode="Lightweight" AllowedFileExtensions="pdf" ></telerik:RadAsyncUpload>
                </EditItemTemplate>
            </telerik:GridTemplateColumn>
        </Columns>
    </MasterTableView>   
</telerik:RadGrid>
protected void gvAuditorium_OnBatchEditCommand(object sender, GridBatchEditingEventArgs e)
        {
 
            if (e.Commands.Count > 0)
            {
                foreach (var editingCommand in e.Commands)
                {
                    int roomId = (int)editingCommand.Item.GetDataKeyValue("RoomId");
                    Hashtable newValues = editingCommand.NewValues;
                    RadAsyncUpload auFileUpload = gvAuditorium.FindControl(gvAuditorium.MasterTableView.ClientID + "_ScanFileName").FindControl("auFileUpload") as RadAsyncUpload;
                    if (auFileUpload != null && auFileUpload.UploadedFiles.Count > 0)
                    {
                        //SAVE FILE
                    }
                    //SAVE DATA TO DB
                }
 
            }
 
        }

If e.Commands.Count == 1, then all OK, but if e.Commands.Count > 1 then RadAsyncUpload auFileUpload = gvAuditorium.FindControl(gvAuditorium.MasterTableView.ClientID +"_ScanFileName").FindControl("auFileUpload") as RadAsyncUpload; get always first edit control.

How can I save files from all edited lines?

1 Answer, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 28 Aug 2017, 12:35 PM

Hello Alexandr,

The batch edit mode works entirely on the client and serializes string data to send to the server so it will fire the BatchEditComamnd.

The way this works is that there is a single edit row that gets moved in the DOM where necessary (where the cell is opened for editing).

This means that there is a single RadAsyncUpload on the client-side rendering of the page.

Thus, an async upload is not supported with batch editing because it requires server operations in order to complete a file upload.

What I can suggest you look into is the following approaches:

  • Extract some functionality in a popup (similar to this demo). You can put the async upload there together with non-required data, for example.
  • Or, create a custom handler for the async upload and save the files in the handler itself instead of using the async upload instance.
  • Or, try using a GridAttachmentColumn as discussed in this forum thread.
  • Or, use the InPlace edit mode instead of the batch edit mode.

 

Regards,

Marin Bratanov
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Alexandr
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Share this question
or