Giter Site home page Giter Site logo

devexpress-examples / aspxgridview-batch-edit-bind-combobox-column-based-on-row-index Goto Github PK

View Code? Open in Web Editor NEW
2.0 56.0 1.0 75 KB

Bind an ASPxGridView Combo Box column's cell editor to data in batch edit mode.

License: Other

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

aspxgridview-batch-edit-bind-combobox-column-based-on-row-index's Introduction

Grid View for ASP.NET Web Forms - How to bind a Combo Box column to data based on the row index in batch edit mode

This example demonstrates how to populate a GridViewDataComboBoxColumn's cell editors at runtime in batch edit mode.

Bind Combo Box Column in Batch Edit Mode

Implementation Details

In batch edit mode, the Grid View does not send requests to the server when a cell editor is activated. Therefore, it is not possible to use the CellEditorInitialize event handler on the server to populate a combo box in each row.

To overcome this limitation, use the combo box editor's callback to populate the editor with items.

  1. Handle the grid's CellEditorInitialize event. In the event handler, assign a new handler to the combo box cell editor's Callback event:

    protected void Grid_CellEditorInitialize(object sender, ASPxGridViewEditorEventArgs e) {
        if (e.Column.FieldName == "C3") {
            ASPxComboBox combo = e.Editor as ASPxComboBox;
            combo.Callback += combo_Callback;
        }
    }
  2. Call the combo box editor's PerformCallback method from the client ASPxClientGridView.BatchEditStartEditing event handler. Pass the current row's visible index as the callback parameter:

    <dx:ASPxGridView ID="Grid" runat="server" KeyFieldName="ID" ... >
        ...
        <ClientSideEvents BatchEditStartEditing="OnBatchEditStartEditing" />
    </dx:ASPxGridView>
    function OnBatchEditStartEditing(s, e) {
        cmb.PerformCallback();
    }
    
  3. Add items to the combo box in the Callback event handler. You can get the current row index from e.Parameter.

    void combo_Callback(object sender, DevExpress.Web.CallbackEventArgsBase e) {
        ASPxComboBox combo = sender as ASPxComboBox;
        for (int i = 0; i < 10; i++) {
            combo.Items.Add(string.Format("Row_{0} Item_{1}", e.Parameter, i), i);
        }
    }

Files to Review

Documentation

More Examples

aspxgridview-batch-edit-bind-combobox-column-based-on-row-index's People

Contributors

devexpressexamplebot avatar eugeniyburmistrov avatar lanadx avatar

Stargazers

 avatar  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.