Git Product home page Git Product logo

gridview-batch-edit-how-to-use-the-upload-control-in-batch-edit-mode-t191714's Introduction

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

gridview-batch-edit-how-to-use-the-upload-control-in-batch-edit-mode-t191714's People

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

elenapeskova

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.