Skip to content

Use the upload control in batch edit mode. All files are stored in memory until you call the update method.

License

Notifications You must be signed in to change notification settings

DevExpress-Examples/asp-net-mvc-grid-use-upload-control-in-batch-edit-mode

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GridView for ASP.NET MVC - How to use the upload control in batch edit mode

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.

Overview

Follow the steps below:

  1. 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();
    });
  2. 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);
    }
  3. 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;
    }
  4. 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) {
        gridView.batchEditApi.SetCellValue($("#hf").val(), "FileName", e.callbackData);
        gridView.batchEditApi.EndEdit();
    }
    function OnTextChanged(s, e) {
        if (s.GetText()) {
            browseClicked = true;
            s.Upload();
        }
    }
  5. 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.

Files to Review

More Examples

About

Use the upload control in batch edit mode. All files are stored in memory until you call the update method.

Topics

Resources

License

Stars

Watchers

Forks

Languages