Giter Site home page Giter Site logo

devexpress-examples / aspxgridview-batch-edit-how-to-use-the-upload-control-in-batch-edit-mode-t191652 Goto Github PK

View Code? Open in Web Editor NEW
0.0 56.0 0.0 17 KB

Use the upload control in batch edit mode.

License: Other

C# 33.67% ASP.NET 66.33%
dotnet aspxgridview asp-net upload

aspxgridview-batch-edit-how-to-use-the-upload-control-in-batch-edit-mode-t191652's Introduction

GridView for ASP.NET Web Forms - 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.

Implementation Details

  1. 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>
  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.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);            
    }
  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;
    }

    This browseClicked flag is set to true when the upload control starts uploading a file and to false when the file has been uploaded or a user starts editing another cell.

  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) {
        grid.batchEditApi.SetCellValue(hf.Get("visibleIndex"), "FileName", e.callbackData);
        grid.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:

    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.

Files to Review

More Examples

*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

aspxgridview-batch-edit-how-to-use-the-upload-control-in-batch-edit-mode-t191652's People

Contributors

devexpressexamplebot avatar lanadx 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  avatar

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.