This demo illustrates the Grid View's built-in data editing functionality.
To enable data editing operations, the grid's KeyFieldName property must be specified. For each allowed data operation (such as inserting, updating or deleting), provide an associated controller action that will apply data changes to Model and return the grid's partial view. You can reference these controller actions by their names using the SettingsEditing.AddNewRowRouteValues, SettingsEditing.UpdateRowRouteValues, and SettingsEditing.DeleteRowRouteValues properties. Note that in actions that handle update and insert operations, you can obtain the edited object using our specific DevExpressEditorsBinder model binder. In the actions handling delete operations, you can get the key value of the deleted row.
To allow end-users to manipulate grid data, add a command column to the grid's column collection and specify which commands (New, Edit, Delete, Update, Cancel) can be used by end-users. To switch a grid row to edit mode, end-users should be allowed to click the Edit command.
The following list highlights built-in edit modes available for the Grid View, from the simplest to the most sophisticated (use the grid's SettingsEditing.Mode property to specify edit mode):
When a row is switched to edit mode, its cells display appropriate editors.
When a row is switched to edit mode, an edit form appears under or instead of the edited row.
Edit Form displays label-editor pairs that correspond to data columns, and the Update/Cancel commands that allow end-users to save or discard the changes made. The EditFormSettings property of data columns contains different settings to arrange label-editor pairs. This provides you with a flexible data editor arrangement mechanism. The default layout of the Edit Form is generated automatically.
Popup Edit Form
When a row is switched to edit mode, Edit Form is displayed as a popup window, which can be dragged and used in modal mode, if required.
By default, if the data entered and submitted by an end-user is invalid due to the Model validation rules, error texts are automatically displayed next to corresponding data field editors within the Grid View. This behavior is controlled by the grid's SettingsEditing.ShowModelErrorsForEditors property. In addition, if Model data is invalid or an error occurs during data changes, you can use the grid's SetEditErrorText method to display a common error text in a special row at the bottom of the grid's edit form.