Skip to content

DevExpress-Examples/asp-net-web-forms-grid-bind-comboboxcolumn-based-on-row-index-in-batch-mode

Repository files navigation

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

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

About

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

Topics

Resources

License

Stars

Watchers

Forks

Contributors 4

  •  
  •  
  •  
  •