Once the DeleteRow method is called, the ASPxGridView.RowDeleting event is raised. It allows you to cancel the delete operation. After a row has been deleted, the ASPxGridView.RowDeleted event is raised.
End-users can delete rows by clicking the Delete command.
ImportsMicrosoft.VisualBasicImportsSystemImportsSystem.DataImportsSystem.ConfigurationImportsSystem.WebImportsSystem.Web.SecurityImportsSystem.Web.UIImportsSystem.Web.UI.WebControlsImportsSystem.Web.UI.WebControls.WebPartsImportsSystem.Web.UI.HtmlControlsImports DevExpress.Web.ASPxGridView
PartialPublicClass _Default
Inherits System.Web.UI.Page
PrivateFunction GetTable() As DataTable
'You can store a DataTable in the session stateDim table As DataTable = TryCast(Session("Table"), DataTable)
If table IsNothingThen
table = New DataTable()
Dim colid As DataColumn = table.Columns.Add("ID", GetType(Int32))
Dim nameid As DataColumn = table.Columns.Add("Name", GetType(String))
table.PrimaryKey = New DataColumn() { colid }
colid.ReadOnly = TrueFor i AsInteger = 0To22Dim aRow As DataRow = table.NewRow()
aRow("ID") = i
aRow("Name") = String.Format("Name{0}", i)
table.Rows.Add(aRow)
Next i
Session("Table") = table
EndIfReturn table
EndFunctionPublicFunction GetLastKey() As Int32
Dim table As DataTable = GetTable()
Dim max As Int32 = Int32.MinValue
ForEach row As DataRow In table.Rows
If Convert.ToInt32(row("ID")) > max Then
max = Convert.ToInt32(row("ID"))
EndIfNext row
Return max
EndFunctionProtectedSub Page_Init(ByVal sender AsObject, ByVal e As EventArgs)
grid.DataSource = GetTable()
grid.KeyFieldName = "ID"
grid.DataBind()
EndSubProtectedSub Page_Load(ByVal sender AsObject, ByVal e As EventArgs)
EndSubProtectedSub grid_RowDeleting(ByVal sender AsObject, ByVal e As DevExpress.Web.Data.ASPxDataDeletingEventArgs)
Dim grid As ASPxGridView = TryCast(sender, ASPxGridView)
Dim table As DataTable = GetTable()
Dim found As DataRow = table.Rows.Find(e.Keys(0))
table.Rows.Remove(found)
Session("Table") = table
e.Cancel = TrueEndSubProtectedSub grid_RowInserting(ByVal sender AsObject, ByVal e As DevExpress.Web.Data.ASPxDataInsertingEventArgs)
Dim grid As ASPxGridView = TryCast(sender, ASPxGridView)
Dim table As DataTable = GetTable()
table.Rows.Add(NewObject() { e.NewValues("ID"), e.NewValues("Name") })
Session("Table") = table
e.Cancel = True
grid.CancelEdit()
EndSubProtectedSub grid_RowUpdating(ByVal sender AsObject, ByVal e As DevExpress.Web.Data.ASPxDataUpdatingEventArgs)
Dim grid As ASPxGridView = TryCast(sender, ASPxGridView)
Dim table As DataTable = GetTable()
Dim found As DataRow = table.Rows.Find(e.Keys(0))
found("Name") = e.NewValues("Name")
Session("Table") = table
e.Cancel = True
grid.CancelEdit()
EndSubProtectedSub grid_InitNewRow(ByVal sender AsObject, ByVal e As DevExpress.Web.Data.ASPxDataInitNewRowEventArgs)
e.NewValues("ID") = GetLastKey() + 1EndSubEndClass