DxGrid.ShowRowDeleteConfirmation(Int32) Method
Displays the delete confirmation dialog for the specified row. If a user confirms the operation, the method raises the DataItemDeleting event.
Namespace: DevExpress.Blazor
Assembly: DevExpress.Blazor.v24.2.dll
NuGet Package: DevExpress.Blazor
#Declaration
public void ShowRowDeleteConfirmation(
int visibleIndex
)
#Parameters
Name | Type | Description |
---|---|---|
visible |
Int32 | The row’s visible index. |
#Remarks
The Grid allows users to add, edit, and delete its data rows.
Tip
For information on how to enable data editing, refer to the following topic: Editing and Validation in Blazor Grid.
The Grid supports the DxGridCommandColumn that contains the predefined New, Edit, and Delete command buttons. Once a user clicks the Delete button, the delete confirmation dialog appears.
You can also create custom command elements inside or outside the Grid. Handle an element’s click event and call the ShowRowDeleteConfirmation
method to display the delete confirmation dialog for the specified row. The DataItemDeleting event fires when a user confirms the delete operation. Handle this event to check user access permissions and delete the data item from the underlying data source.
The Grid also includes the following edit-related methods:
- StartEditNewRowAsync
- Starts editing a new row.
- StartEditRowAsync | StartEditDataItemAsync
- Start editing the specified row or data item.
- ShowDataItemDeleteConfirmation
- Displays the delete confirmation dialog for the specified data item.
Note
The Grid bound to an Instant Feedback Data Source or GridShow
method, call the Wait
The following example creates buttons used to edit and delete a row whose visible index is 0
:
@using Microsoft.EntityFrameworkCore
@inject IDbContextFactory<NorthwindContext> NorthwindContextFactory
@implements IDisposable
<DxGrid Data="GridDataSource"
EditModelSaving="OnEditModelSaving"
DataItemDeleting="OnDataItemDeleting"
KeyFieldName="EmployeeId"
EdiMode="GridEditMode.EditRow"
@ref="MyGrid">
<Columns>
<DxGridCommandColumn Width="150" />
<DxGridDataColumn FieldName="FirstName" />
<DxGridDataColumn FieldName="LastName" />
<DxGridDataColumn FieldName="Title" />
<DxGridDataColumn FieldName="HireDate" />
</Columns>
</DxGrid>
<br />
<DxButton Click="() => MyGrid.StartEditRowAsync(0)">Edit First Row</DxButton>
<DxButton Click="() => MyGrid.ShowRowDeleteConfirmation(0)">Delete First Row</DxButton>
@code {
IEnumerable<object> GridDataSource { get; set; }
NorthwindContext Northwind { get; set; }
IGrid MyGrid { get; set; }
protected override async Task OnInitializedAsync() {
Northwind = NorthwindContextFactory.CreateDbContext();
GridDataSource = await Northwind.Employees.ToListAsync();
}
async Task OnEditModelSaving(GridEditModelSavingEventArgs e) {
var editModel = (Employee)e.EditModel;
// Assign changes from the edit model to the data item.
if (e.IsNew)
await Northwind.AddAsync(editModel);
else
e.CopyChangesToDataItem();
// Post changes to the database.
await Northwind.SaveChangesAsync();
// Reload the entire Grid.
GridDataSource = await Northwind.Employees.ToListAsync();
}
async Task OnDataItemDeleting(GridDataItemDeletingEventArgs e) {
// Remove the data item from the database.
Northwind.Remove(e.DataItem);
await Northwind.SaveChangesAsync();
// Reload the entire Grid.
GridDataSource = await Northwind.Employees.ToListAsync();
}
public void Dispose() {
Northwind?.Dispose();
}
}