aspnet-401080-components-grid-view-concepts-edit-data-delete-records.md
This topic illustrates how to delete the ASPxGridView‘s records. Use the instructions below to manage records when the grid is in the Inline , EditForm , EditFormAndDisplayRow , and PopupEditForm edit modes (Mode). Refer to the following topic for more information on how to delete records in batch edit mode: Batch Edit Mode.
<dx:ASPxGridView ID="ASPxGridView1" >
<SettingsEditing Mode="EditForm" />
...
</dx:ASPxGridView>
Note
false to prevent users from deleting records.Use any of the following UI elements that allow users to delete records:
Create a command column (GridViewCommandColumn) and use the ShowDeleteButton property to display the Delete command button in the grid. Use the DeleteButton object to access the Delete command button’s settings.
<dx:ASPxGridView ID="ASPxGridView1" runat="server" KeyFieldName="OrderID" >
<Columns>
<dx:GridViewCommandColumn VisibleIndex="0" ShowDeleteButton="True" >
</dx:GridViewCommandColumn>
...
</Columns>
<SettingsCommandButton>
<DeleteButton ButtonType="Button" RenderMode="Button" >
</NewButton>
</SettingsCommandButton>
</dx:ASPxGridView>
Create custom UI elements that call the following APIs to delete records:
The ASPxGridView.DeleteRow method (server side).
The ASPxClientGridView.DeleteRow method (client side).
The DeleteRowByKey(key) method (client side).
Use the ASPxGridBehaviorSettings.ConfirmDelete property to specify whether the grid displays the delete confirmation dialog. The ASPxGridTextSettings.ConfirmDelete property specifies the delete confirmation dialog’s text.
<dx:ASPxGridView ID="ASPxGridView1" runat="server" >
<SettingsBehavior ConfirmDelete="true" />
<SettingsText ConfirmDelete="Custom Text" />
<Columns>
<dx:GridViewCommandColumn ShowDeleteButton="true" VisibleIndex="0" >
...
</Columns>
</dx:ASPxGridView>
The grid sends a callback to the server and raises the BeginCallback and EndCallback events when you click a command button or call the DeleteRow(visibleIndex) or DeleteRowByKey(key) methods. You can handle the BeginCallback event and check the e.command property to determine which user action triggered the callback.
<dx:ASPxGridView ID="ASPxGridView1" runat="server" ClientInstanceName="gv" >
<ClientSideEvents BeginCallback="OnBeginCallback" />
<Columns>
...
</Columns>
</dx:ASPxGridView>
function OnBeginCallback(s, e) {
if (e.command == "DELETEROW") {
// your code
}
}
Note
Do not send parallel callbacks to controls because it can cause unpredictable results (the controls may return callback results at different times). The following topic describes the recommended approach: Callbacks.
The following example illustrates how to use subsequent callbacks to create a new record after you delete a row:
<dx:ASPxGridView ID="ASPxGridView1" runat="server" ClientInstanceName="gridView" ...>
...
<ClientSideEvents BeginCallback="OnBeginCallback" EndCallback="OnEndCallback"/>
</dx:ASPxGridView>
var deleted = false;
function OnEndCallback(s, e) {
if (e.command == 'DELETEROW' & deleted == true) {
deleted = false;
gv.AddNewRow();
}
}
function OnBeginCallback(s, e) {
if (e.command == 'DELETEROW')
deleted = true;
}
The grid raises the following server-side events when you delete a record:
The ASPxGridView.RowDeleting event. The grid raises this event when an end user attempts to remove the record. Set the e.Cancel argument to true to prevent this action.
The ASPxGridView.RowDeleted event occurs when the record is removed from the database.