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.
Follow the steps below:
-
Place an upload control to a column's edit item template:
c.SetEditItemTemplateContent(container => { Html.DevExpress().UploadControl(ucSettings => { ucSettings.Name = "uc"; ucSettings.CallbackRouteValues = new { Controller = "Home", Action = "UploadControlUploadFile" }; ucSettings.UploadMode = UploadControlUploadMode.Advanced; ucSettings.Width = Unit.Percentage(100); ucSettings.ClientSideEvents.TextChanged = "OnTextChanged"; ucSettings.ClientSideEvents.FileUploadComplete = "OnFileUploadComplete"; }).Render(); });
-
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").val(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; }
-
Handle the upload control's client-side
TextChanged
andFileUploadComplete
events to automatically upload the selected file and update the cell value after:function OnFileUploadComplete(s, e) { gridView.batchEditApi.SetCellValue($("#hf").val(), "FileName", e.callbackData); gridView.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:public ActionResult UploadControlUploadFile() { var visibleIndex = Convert.ToInt32(Request.Params["hf"]); UploadControlExtension.GetUploadedFiles("uc", null, (s,e) => { var name = e.UploadedFile.FileName; e.CallbackData = name; if (Helper.Files.ContainsKey(visibleIndex)) Helper.Files[visibleIndex] = e.UploadedFile.FileBytes; else Helper.Files.Add(visibleIndex, e.UploadedFile.FileBytes); }); return null; }
Now you can access all the uploaded files in the batch action method. Clear the session storage after you have updated the files.