GithubHelp home page GithubHelp logo

devexpress-examples / how-to-move-selected-rows-from-the-aspxgridview-into-another-aspxgridview-e2636 Goto Github PK

View Code? Open in Web Editor NEW
1.0 55.0 2.0 38.69 MB

Move selected rows from one grid to another on a custom button click and update data sources on the server.

License: Other

C# 28.49% ASP.NET 48.75% Visual Basic .NET 22.76%
dotnet aspxgridview asp-net buttons callback selection

how-to-move-selected-rows-from-the-aspxgridview-into-another-aspxgridview-e2636's Introduction

Grid View for ASP.NET Web Forms - How to move selected rows between grid controls

This example demonstrates how to move selected rows from one grid to another on a custom button click and update data sources on the server.

Move selected grid rows

Overview

Create two grid controls and add custom moving buttons to the page. Use the client-side PerformCallback method to send custom callbacks to the server when a user clicks the corresponding button. Based on an action, create a command and pass it as a parameter.

var command = null;
function AddSelectedRows() {
    command = 'addSelectedRows';
    UpdateTargetGrid();
}

function UpdateTargetGrid() {
    if (command != null)
        targetGrid.PerformCallback(command);
    else {
        targetGrid.Refresh();
    }
}

On the server, the PerformCallback method raises the CustomCallback event. In the CustomCallback event handler, call the GetSelectedFieldValues method to obtain the selected rows. Update the data sources of the grids based on the command passed to the server.

protected void TargetGrid_CustomCallback(object sender, DevExpress.Web.ASPxGridViewCustomCallbackEventArgs e) {
    rowValues = new List<object>();
    
    switch (e.Parameters) {
        case "addSelectedRows":
            rowValues = SourceGrid.GetSelectedFieldValues(fieldNames);
            var categoryIDs = new StringBuilder();
            for (int i = 0; i < rowValues.Count(); i++) {
                var categoryID = (rowValues[i] as object[])[0];
                if (i < rowValues.Count() - 1)
                    categoryIDs.AppendFormat("{0}, ", categoryID);
                else
                    categoryIDs.Append(categoryID);
            }
            if (categoryIDs.Length > 0) {
                SourceDS.DeleteCommand = string.Format("DELETE FROM [Categories] WHERE [CategoryID] IN ({0})", categoryIDs);
                SourceDS.Delete();
                
                foreach (object[] rowValue in rowValues) {
                    TargetDS.InsertCommand = string.Format(
                        "INSERT INTO [CategoriesUpdated] ([CategoryID], [CategoryName], [Description]) VALUES ({0}, '{1}', '{2}')", 
                        rowValue[0], rowValue[1], rowValue[2]);
                    TargetDS.Insert();
                }
                TargetGrid.DataBind();
            }
            break;
        // ...
    }
}

Files to Review

Documentation

More Examples

how-to-move-selected-rows-from-the-aspxgridview-into-another-aspxgridview-e2636's People

Contributors

devexpressexamplebot avatar devexpresssupportteam avatar elenapeskova avatar zabelin-vladimir avatar

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

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.