Skip to content

DevExpress-Examples/aspxgridview-delete-selected-rows

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Grid View for ASP.NET Web Forms - How to Delete Selected Rows in a Grid

The example shows how to delete the selected rows of an ASPxGridView that is bound to an in-memory DataSource.

A grid with selected rows to be deleted

Use the client-side PerformCallback method to send custom callbacks to the server when a user clicks the Delete button.

function OnClickButtonDel(s, e) {
    grid.PerformCallback('Delete');
}
...
<dx:ASPxButton ID="buttonDel" AutoPostBack="false" 
               runat="server" Text="Delete">
    <ClientSideEvents Click="OnClickButtonDel"/>
</dx:ASPxButton>

On the server, the PerformCallback method raises the CustomCallback event.

In the CustomCallback event handler, call the GetSelectedFieldValues method to obtain the selected rows. Then, call the Remove method for each selected row.

protected void gridView_CustomCallback(object sender, ASPxGridViewCustomCallbackEventArgs e) {
    if(e.Parameters == "Delete") {
        table = GetTable();
        List<Object> selectItems = grid.GetSelectedFieldValues("ID");
        foreach(object selectItemId in selectItems) {
            table.Rows.Remove(table.Rows.Find(selectItemId));
        }
        grid.DataBind();
        grid.Selection.UnselectAll();
    }
}

Files to Look At

Documentation

More Examples

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)