The example illustrates how to delete selected rows of the ASPxGridView bound to an in-memory data source.
See Also:
View Example
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();
}
}
<head runat="server">
<script type="text/javascript">
function OnClickButtonDel(s, e) {
grid.PerformCallback('Delete');
}
</script>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<dx:ASPxGridView ID="grid" KeyFieldName="ID" runat="server" AutoGenerateColumns="False"
OnCellEditorInitialize="gridView_CellEditorInitialize" OnRowInserting="gridView_RowInserting"
OnRowUpdating="gridView_RowUpdating" ClientInstanceName="grid"
OnCustomCallback="gridView_CustomCallback"
ondatabinding="grid_DataBinding" >
<Columns>
<dx:GridViewCommandColumn VisibleIndex="0" ShowSelectCheckbox="True" ShowEditButton="True" ShowNewButton="True" ShowUpdateButton="True">
<FooterTemplate>
<dx:ASPxButton ID="buttonDel" AutoPostBack="false" runat="server" Text="Delete">
<ClientSideEvents Click="OnClickButtonDel"/>
</dx:ASPxButton>
</FooterTemplate>
</dx:GridViewCommandColumn>
<dx:GridViewDataTextColumn FieldName="ID" ReadOnly="True" VisibleIndex="1">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="Data" VisibleIndex="2">
</dx:GridViewDataTextColumn>
</Columns>
<Settings ShowFooter="True" />
</dx:ASPxGridView>
</div>
</form>
</body>
<head runat="server">
<script type="text/javascript">
function OnClickButtonDel(s, e) {
grid.PerformCallback('Delete');
}
</script>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<dx:ASPxGridView ID="grid" KeyFieldName="ID" runat="server" AutoGenerateColumns="False"
OnCellEditorInitialize="gridView_CellEditorInitialize" OnRowInserting="gridView_RowInserting"
OnRowUpdating="gridView_RowUpdating" ClientInstanceName="grid"
OnCustomCallback="gridView_CustomCallback"
ondatabinding="grid_DataBinding" >
<Columns>
<dx:GridViewCommandColumn VisibleIndex="0" ShowSelectCheckbox="True" ShowEditButton="True" ShowNewButton="True" ShowUpdateButton="True">
<FooterTemplate>
<dx:ASPxButton ID="buttonDel" AutoPostBack="false" runat="server" Text="Delete">
<ClientSideEvents Click="OnClickButtonDel"/>
</dx:ASPxButton>
</FooterTemplate>
</dx:GridViewCommandColumn>
<dx:GridViewDataTextColumn FieldName="ID" ReadOnly="True" VisibleIndex="1">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="Data" VisibleIndex="2">
</dx:GridViewDataTextColumn>
</Columns>
<Settings ShowFooter="True" />
</dx:ASPxGridView>
</div>
</form>
</body>
Protected Sub gridView_CustomCallback(ByVal sender As Object, ByVal e As ASPxGridViewCustomCallbackEventArgs)
If e.Parameters = "Delete" Then
table = DirectCast(Session("table"), DataTable)
Dim selectItems As List(Of Object) = grid.GetSelectedFieldValues("ID")
For Each selectItemId As Object In selectItems
table.Rows.Remove(table.Rows.Find(selectItemId))
Next selectItemId
grid.DataBind()
grid.Selection.UnselectAll()
End If
End Sub