CLR: .Net / Mono / Boo / Otros CLR > ASP .NET
Coger valores actualizados de un Cell
(1/1)
kaidok:
Partiendo del siguiente código:
--- Código: Text --- 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
Donde Adap es un DataAdapter rellenado, Ds un DataSet y DataGrid1 el DataGrid.
Me gustaría saber por que al tomar los datos mediante el uso e.Items.Cells no cojo como se encuentra el TextBox en ese mismo instante sino el valor inicial que tenía, haciendo imposible por tanto cualquier actualización. Está comprobado además que el error ha de estar relacionado con ese punto, ya que por ejemplo si asigno un valor directamente, (por ejemplo dr(2)="prueba", la actualización sí que se realiza correctamente.
¿Hay alguna operación extra que deba hacer para que con e.Items.Cells coja el valor actual y no el inicial?
Un saludo.
sergiotarrillo:
Haz probado usando FindControl?
Revisa este artículo: Adding a New Record to the DataGrid.
Saludos,
Navegación
Ir a la versión completa