Skip to content

Use the check box state to enable or disable the grid's cell edit functionality in batch edit mode.

License

Notifications You must be signed in to change notification settings

DevExpress-Examples/asp-net-mvc-grid-enable-and-disable-batch-editing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GridView for ASP.NET MVC - 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.

Allow Edit Checkbox

Overview

Follow the steps below:

  1. 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 command column and set its ShowNewButtonInHeader and ShowDeleteButton properties to true.

    @Html.DevExpress().GridView(settings => {
        // ...
        settings.SettingsEditing.Mode = GridViewEditingMode.Batch;
        settings.CommandColumn.Visible = true;
        settings.CommandColumn.ShowNewButtonInHeader = true;
        settings.CommandColumn.ShowDeleteButton = true;
        // ...
    }).Bind(Model).GetHtml()
  2. Add a check box and handle its client-side CheckedChanged event. In the handler, get the current state of the check box and assign the state to a flag variable.

    @Html.DevExpress().CheckBox(settings => {
        settings.Name = "AllowEditCB";
        settings.Text = "Allow Editing";
        settings.Properties.ClientSideEvents.CheckedChanged = "OnAllowEditChanged";
    }).GetHtml()
    var allowEdit = false;
    function OnAllowEditChanged(s, e) {
        allowEdit = s.GetValue();
    }
  3. Handle the grid's client-side BatchEditStartEditing, BatchEditRowInserting, and BatcshEditRowDeleting events. In the handler, cancel the current edit operation based on the flag variable value.

    @Html.DevExpress().GridView(settings => {
        // ...
        settings.ClientSideEvents.BatchEditRowDeleting = "OnEditing";
        settings.ClientSideEvents.BatchEditRowInserting = "OnEditing";
        settings.ClientSideEvents.BatchEditStartEditing = "OnEditing";
    })
    function OnEditing(s, e) {
        e.cancel = !allowEdit;
    }

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

Use the check box state to enable or disable the grid's cell edit functionality in batch edit mode.

Topics

Resources

License

Stars

Watchers

Forks