Skip to main content

Adding and Deleting Records

  • 2 minutes to read

Creating and Initializing New Records

End-users can create new records using the New command.

To allow end-users to add new records, create a command row, access the New command’s settings by the ASPxVerticalGridCommandButtonSettings.NewButton property and set the VerticalGridCommandRow.ShowNewButton property to true.

ASPxVerticalGrid-NewButton

To create records in code, use the client ASPxClientVerticalGrid.AddNewRecord method. This method switches the ASPxVerticalGrid to batch edit mode and allows the values of the new record to be edited.

To initialize record values in code, handle the ASPxVerticalGrid.InitNewRecord event.

Example:

In this example, the ASPxVerticalGrid.InitNewRecord event is handled to initialize the new record’s field values with default values.

The image below shows the result:

ASPxVerticalGrid-InitNewRecord

protected void VerticalGrid_InitNewRecord(object sender, DevExpress.Web.Data.ASPxDataInitNewRowEventArgs e)
{
    e.NewValues["ProductName"] = "Sample name";
    e.NewValues["UnitPrice"] = 10;
}

Adding Records

To add a new record to the underlying data source, call the ASPxClientVerticalGrid.UpdateEdit (or ASPxClientVerticalGrid.UpdateEdit) method. End-users can do this by clicking the Save Changes button (the Update command).

ASPxVerticalGrid-AddNewRecord

You can also implement record validation. For information, see Record Validation and Error Indication.

After a new record has been added to ASPxVerticalGrid, the ASPxVerticalGrid.RecordInserted event is raised. To cancel the insert operation, handle the ASPxVerticalGrid.RecordInserting event.

Deleting Records

End-users can delete records using the Delete command. To do this in code, use the client ASPxClientVerticalGrid.DeleteRecord method.

After a record has been deleted, the ASPxVerticalGrid.RecordDeleted event is raised. To cancel the delete operation, handle the ASPxVerticalGrid.RecordDeleting event.

To allow an end-user to cancel the delete operation, enable the ASPxGridBehaviorSettings.ConfirmDelete option. In this case, when the user deletes a record, the Confirm Delete window is automatically displayed.

ASPxVerticalGrid-ConfirmDelete

The text displayed within the Confirm Delete window can be specified using the ASPxGridTextSettings.ConfirmDelete property.