Skip to main content
A newer version of this page is available. .

ASPxClientGridView.BatchEditStartEditing Event

Occurs when a grid switches to batch edit mode.

Declaration

BatchEditStartEditing: ASPxClientEvent<ASPxClientGridViewBatchEditStartEditingEventHandler<ASPxClientGridView>>

Event Data

The BatchEditStartEditing event's data class is ASPxClientGridViewBatchEditStartEditingEventArgs. The following properties provide information specific to this event:

Property Description
cancel Gets or sets a value indicating whether the action which raised the event should be canceled. Inherited from ASPxClientCancelEventArgs.
focusedColumn Gets the grid column that owns a cell that is about to be edited.
key Gets the row’s key.
rowValues Gets a hashtable that maintains information about editable cells.
visibleIndex Gets the visible index of the row whose cells are about to be edited.

Remarks

The BatchEditStartEditing event is raised when the grid enters the edit mode (for a cell/row) due to an end-user interaction or programmatic call to the ASPxClientGridViewBatchEditApi.StartEdit method. The event provides arguments that allow you to prevent switching a particular cell to the edit mode.

When the GridViewBatchEditSettings.EditMode property is set to Cell, you can set the ASPxClientCancelEventArgs.cancel argument to true to prevent editing the current cell.


function Grid_BatchEditStartEditing(s, e) {
   ...
   e.cancel = true;
}

When the GridViewBatchEditSettings.EditMode property is set to Row, you can prevent switching particular cells to edit mode using the ASPxClientGridViewBatchEditStartEditingEventArgs.rowValues event argument. This is a hashtable that maintains information about editable cells. You can prevent displaying editors for particular cells by removing the corresponding entries from rowValues.


function Grid_BatchEditStartEditing(s, e) {
   ...
   delete e.rowValues[myColumn.index];
}

Example

This example demonstrates how to cancel editing or disable the editor conditionally for the grid when batch editing is in use. It is possible to execute your logic either on the client or server side for a complex business model.

Then, handle the grid’s client-side ASPxClientGridView.BatchEditStartEditing event to either cancel the edit operation using the e.cancel property:


if (condition) e.cancel = true;

or disable the editor by obtaining its client instance:


var editor = s.GetEditor(e.focusedColumn.fieldName);
editor.SetEnabled(condition);

The custom server-side logic can be executed in the CustomJSProperties event handler:


protected void ASPxGridView1_CustomJSProperties(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewClientJSPropertiesEventArgs e) {
    var clientData = new Dictionary<int, object>();
    var grid = sender as ASPxGridView;
    for (int i = 0; i < grid.VisibleRowCount; i++) {
        var rowValues = grid.GetRowValues(i, new string[] { "ID", "ServerSideExample" }) as object[];

        var key = Convert.ToInt32(rowValues[0]);
        if (key % 2 != 0)
            clientData.Add(key, "ServerSideExample");
    }
    e.Properties["cp_cellsToDisable"] = clientData;
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register Assembly="DevExpress.Web.v14.1, Version=14.1.13.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxGridView" TagPrefix="dx" %>

<%@ Register assembly="DevExpress.Web.v14.1, Version=14.1.13.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxEditors" tagprefix="dx" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        function OnBatchStartEdit(s, e) {
            //client processing
            var keyIndex = s.GetColumnByField("ID").index;
            var key = e.rowValues[keyIndex].value;

            var condition = key % 2 == 0;

            if (e.focusedColumn.fieldName == "ClientSideCancel") //cancel example
                if (!condition) e.cancel = true;

            //server preprocessing
            if (typeof s.cp_cellsToDisable[key] != "undefined" && s.cp_cellsToDisable[key] == e.focusedColumn.fieldName)
                e.cancel = true;
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <dx:ASPxGridView ID="ASPxGridView1" runat="server" KeyFieldName="ID" OnCustomJSProperties="ASPxGridView1_CustomJSProperties">
            <SettingsEditing Mode="Batch"></SettingsEditing>
            <ClientSideEvents BatchEditStartEditing="OnBatchStartEdit" />
        </dx:ASPxGridView>
    </div>
    </form>
</body>
</html>
See Also