Sub ItemsGrid_Cancel(sender As Object, e As DataGridCommandEventArgs)
' Set the EditItemIndex property to -1 to exit editing mode.
' Be sure to rebind the DateGrid to the data source to refresh
' the control.
DataGrid1.EditItemIndex = -1
DataGrid1.DataBind()
End Sub
Sub ItemsGrid_Update(sender As Object, e As DataGridCommandEventArgs)
' For bound columns, the edited value is stored in a TextBox.
' The TextBox is the 0th control in a cell's Controls collection.
' Each cell in the Cells collection of a DataGrid item represents
' a column in the DataGrid control.
Dim qtyText As TextBox = CType(e.Item.Cells(3).Controls(0), TextBox)
Dim priceText As TextBox = CType(e.Item.Cells(4).Controls(0), TextBox)
' Retrieve the updated values.
Dim item As String = e.Item.Cells(2).Text
Dim qty As String = qtyText.Text
Dim price As String = priceText.Text
Dim dr As DataRow
Dim Cart As DataTable=Ds.Tables(0)
Dim CartView As New DataView(Cart)
' With a database, use an update command to update the data.
' Because the data source in this example is an in-memory
' DataTable, delete the old row and replace it with a new one.
' Remove the old entry and clear the row filter.
CartView.RowFilter = "Id='" & item & "'"
If CartView.Count > 0 Then
Cart.Rows(0).Delete()
End If
CartView.RowFilter = ""
' ***************************************************************
' Insert data validation code here. Be sure to validate the
' values entered by the user before converting to the appropriate
' data types and updating the data source.
' ***************************************************************
' Add the new entry.
dr = Cart.NewRow()
dr(0) = item
dr(1) = qty
' If necessary, remove the '$' character from the price before
' converting it to a Double.
dr(2) = price
Cart.Rows.Add(dr)
' Set the EditItemIndex property to -1 to exit editing mode.
' Be sure to rebind the DateGrid to the data source to refresh
' the control.
DataGrid1.EditItemIndex = -1
Adap.Update(Ds,"Tabla1")
DataGrid1.DataBind()
Ds.AcceptChanges()
End Sub