Grid View for ASP.NET Web Forms - How to enable or disable the cell edit functionality in batch mode based on a condition
This example demonstrates how to use the check box state to enable or disable the grid's cell edit functionality in batch edit mode.
Follow the steps below:
-
Create the Grid View control and populate it with columns. Set the grid's SettingsEditing.Mode property to
Batch
to enable the batch edit mode. Add a GridViewCommandColumn and set its ShowNewButtonInHeader and ShowDeleteButton properties totrue
.<dx:ASPxGridView ID="ASPxGridView1" runat="server" KeyFieldName="ID" ...> <SettingsEditing Mode="Batch" /> <Columns> <dx:GridViewCommandColumn ShowNewButtonInHeader="true" ShowDeleteButton="true" /> <!-- ... --> </Columns> </dx:ASPxGridView>
-
Add a check box and handle its client-side CheckedChanged event. In the handler, create a flag variable, get the current state of the check box, and assign the state to the flag variable.
<dx:ASPxCheckBox ID="ASPxCheckBox1" runat="server" Text="Allow edit"> <ClientSideEvents CheckedChanged="OnAllowEditChanged" /> </dx:ASPxCheckBox>
var allowEdit = false; function OnAllowEditChanged(s, e) { allowEdit = s.GetValue(); }
-
Handle the grid's client-side BatchEditStartEditing, BatchEditRowInserting, and BatchEditRowDeleting events. In the handler, cancel the current edit operation based on the flag variable value.
<dx:ASPxGridView ID="ASPxGridView1" runat="server" ...> <!-- ... --> <ClientSideEvents BatchEditStartEditing="OnEditing" BatchEditRowDeleting="OnEditing" BatchEditRowInserting="OnEditing" /> </dx:ASPxGridView>
function OnEditing(s, e) { e.cancel = !allowEdit; }
- Default.aspx (VB: Default.aspx)
(you will be redirected to DevExpress.com to submit your response)