Javascript – Changing value in ASPxGridView.OnCustomCallback when already in edit mode will not save the new value

asp.netaspxgridviewdevexpressjavascript

I have an ASPxGridView shown to the user with an edit command button. When the user clicks the edit command button the selected row will change into the edit form.

In the edit form I have a control which when clicked will do a custom callback through javascript, the custom callback handler will then change a value on the selected row and call UpdateEdit() to save the changed value and return to the regular grid view layout.

However the new value is never saved to the underlying datasource, in fact if I debug the DataSourceControl's ExecuteUpdate method I see the updated value in the oldValues collection and the values collection has the original value.

The javascript that is called from the control in the editform:

javascript:grid.PerformCallback("CloseOrder");

The custom callback handler which runs on the server:

protected void gdOrders_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e) {
    if (e.Parameters == "CloseOrder") {
        var row = gdOrders.GetDataRow(gdOrders.EditingRowVisibleIndex);
        row["Status"] = 5;
        gdOrders.UpdateEdit();
    }
}

Best Answer

I found the following solution to work. I'm not sure it's the correct way but it works.

protected void gdOrders_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e) {
    if (e.Parameters == "CloseOrder") {                
        gdOrders.RowUpdating += (s, e1) => { e1.NewValues["Status"] = 5; };
        gdOrders.UpdateEdit();
    }
}
Related Topic