This example illustrates how to use the upload control in batch edit mode. Note that all files are stored in memory until you call the update method.
-
Place an upload control to a column's edit item template:
<dx:GridViewDataTextColumn FieldName="FileName" Width="200"> <EditItemTemplate> <dx:ASPxUploadControl ID="ASPxUploadControl1" runat="server" UploadMode="Advanced" Width="280px" ClientInstanceName="uc" FileUploadMode="OnPageLoad" OnFileUploadComplete="ASPxUploadControl1_FileUploadComplete"> <ClientSideEvents TextChanged="OnTextChanged" FileUploadComplete="OnFileUploadComplete" /> </dx:ASPxUploadControl> </EditItemTemplate> </dx:GridViewDataTextColumn>
-
Handle the grid's client-side BatchEditStartEditing event to set the grid's cell values to the upload control. Use the rowValues argument property to get the focused cell value:
function OnBatchStartEditing(s, e) { browseClicked = false; hf.Set("visibleIndex", e.visibleIndex); var fileNameColumn = s.GetColumnByField("FileName"); if (!e.rowValues.hasOwnProperty(fileNameColumn.index)) return; var cellInfo = e.rowValues[fileNameColumn.index]; setTimeout(function () { SetUCText(cellInfo.value); }, 0); }
-
Handle the grid's client-side BatchEditConfirmShowing event to prevent data loss on the upload control's callbacks:
function OnBatchConfirm(s, e) { e.cancel = browseClicked; }
This
browseClicked
flag is set totrue
when the upload control starts uploading a file and tofalse
when the file has been uploaded or a user starts editing another cell. -
Handle the upload control's client-side TextChanged and FileUploadComplete events to automatically upload the selected file and update the cell value after:
function OnFileUploadComplete(s, e) { grid.batchEditApi.SetCellValue(hf.Get("visibleIndex"), "FileName", e.callbackData); grid.batchEditApi.EndEdit(); } function OnTextChanged(s, e) { if (s.GetText()) { browseClicked = true; s.Upload(); } }
-
Handle the upload control's FileUploadComplete event to store the uploaded file in the session:
protected void ASPxUploadControl1_FileUploadComplete(object sender, FileUploadCompleteEventArgs e) { var name = e.UploadedFile.FileName; e.CallbackData = name; if (Files.ContainsKey(hiddenField["visibleIndex"])) Files[hiddenField["visibleIndex"]] = e.UploadedFile.FileBytes; else Files.Add(hiddenField["visibleIndex"], e.UploadedFile.FileBytes); }
Now you can access all the uploaded files in the BatchUpdate event handler. Clear the session storage after you have updated the files.
- Default.aspx (VB: Default.aspx)
- Default.aspx.cs (VB: Default.aspx.vb)
*Grid View for ASP.NET Web Forms - How to implement an edit item template in batch mode *GridView for ASP.NET MVC - How to use the upload control in batch edit mode