This example handles the client-side FocusedCellChanging event to disable the cell edit action in batch edit mode based on a condition defined in code.
Limitation: This technique is not applicable if you set the EditMode property to Row. A user can focus and edit any cell in a row switched to edit mode except for cells that belong to read-only columns (the column's GridViewDataColumn.ReadOnly property is set to
true
).
The following client-side FocusedCellChanging event handler sets the e.Cancel property to true
to cancel the focus action and subsequent edit operations for cells in specific columns and rows. The code uses the e.cellInfo event property to get information about the clicked cell.
function onFocusedCellChanging(s, e) {
if (e.cellInfo.column.name == "command") e.cancel = true;
else if (e.cellInfo.column.fieldName == "SupplierID") e.cancel = true;
else if (
e.cellInfo.column.fieldName == "UnitsInStock" &&
(e.cellInfo.rowVisibleIndex < 3 || e.cellInfo.rowVisibleIndex > 7)
)
e.cancel = true;
else if (
e.cellInfo.column.fieldName == "UnitPrice" &&
s.batchEditApi.GetCellValue(e.cellInfo.rowVisibleIndex, "UnitPrice") > 22
)
e.cancel = true;
}
- Default.aspx (VB: Default.aspx)
- Default.aspx.cs (VB: Default.aspx.vb)
- Grid View for ASP.NET Web Forms - A simple batch editing implementation
- Grid View for ASP.NET Web Forms - Editing an in-memory dataset
(you will be redirected to DevExpress.com to submit your response)