Problema con instancia for
Publicado por Andres (1 intervención) el 24/05/2018 13:34:30
Hola a todos tengo un problema con un instancia for, mi programa carga manualmente un gridview con numeros de items (acorde a las filas), tengo un metodo para eliminar una de esas filas (previamente seleccionada)
y modifica el numero de item a travez del evento RowDataBound....
la primera vez que ejecuto el borrar funciona correctamente, despues de esa vez las siguientes empieza a modificarse mal el numero de items.... haciendo un seguimiento ingresando puntos de interrupcion en el programa detecte que despues del segundo intento de borrado a la hora de buscar el item adentro del for ("Dim x As Integer = Convert.ToInt32(e.Row.Cells(1).Text)") este contiene los valores de la anterior vez que ejecute el metodo eliminarfila()... tengo un metodo que actualiza la tabla
pero cuando lo ingreso dentro del RowDataBound el for entra en un ciclo de bucle, asique no se como solucionar mi problema, alguien tiene alguna idea?, desde ya muchisimas gracias por sus tiempos!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Sub eliminarfila()
Dim tempDetalle As DataTable
tempDetalle = ViewState("detalle")
Dim nRec As DataRow
nRec = tempDetalle.Rows(Convert.ToInt32(gvDetallePedido.SelectedRow.Cells(1).Text) - 1)
Dim ubicacion As Integer
ubicacion1 = Convert.ToInt32(gvDetallePedido.SelectedRow.Cells(1).Text)
ubicacion = gvDetallePedido.Rows.Count - (gvDetallePedido.SelectedValue() - 1)
Dim descontar As Decimal = Convert.ToDecimal(gvDetallePedido.SelectedRow.Cells(4).Text)
tempDetalle.Rows.Remove(nRec)
gvDetallePedido.DataSource = tempDetalle
gvDetallePedido.DataBind()
If (gvDetallePedido.Rows.Count() > 1) Then
dTotal = dTotal - descontar
gvDetallePedido.Visible = True
Me.Panel2.Visible = False
Me.btnConfirmar.Visible = False
Me.btnCancelar.Visible = False
Me.txtItem.Text = "1"
gvDetallePedido.DataBind()
Else
gvDetallePedido.Visible = False
End If
End Sub
y modifica el numero de item a travez del evento RowDataBound....
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
Protected Sub gvDetallePedido_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvDetallePedido.RowDataBound
If Me.txtItem.Text = "1" Then
If (e.Row.RowType = DataControlRowType.DataRow) Then
For Counter As Integer = 1 To 1
Dim x As Integer = Convert.ToInt32(e.Row.Cells(1).Text)
Dim x2 As String = e.Row.Cells(3).Text
If (x > ubicacion1) Then
e.Row.Cells(1).Text = (x - 1).ToString()
End If
Next Counter
End If
If e.Row.RowType = DataControlRowType.Footer Then
e.Row.Cells(2).Text = "Total:"
e.Row.Cells(3).Text = dTotal.ToString("c")
e.Row.Cells(3).HorizontalAlign = HorizontalAlign.Right
e.Row.Font.Bold = True
End If
Else
If e.Row.RowType = DataControlRowType.DataRow Then
dTotal += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "precio"))
End If
If e.Row.RowType = DataControlRowType.Footer Then
e.Row.Cells(2).Text = "Total:"
e.Row.Cells(3).Text = dTotal.ToString("c")
e.Row.Cells(3).HorizontalAlign = HorizontalAlign.Right
e.Row.Font.Bold = True
End If
End If
End Sub
la primera vez que ejecuto el borrar funciona correctamente, despues de esa vez las siguientes empieza a modificarse mal el numero de items.... haciendo un seguimiento ingresando puntos de interrupcion en el programa detecte que despues del segundo intento de borrado a la hora de buscar el item adentro del for ("Dim x As Integer = Convert.ToInt32(e.Row.Cells(1).Text)") este contiene los valores de la anterior vez que ejecute el metodo eliminarfila()... tengo un metodo que actualiza la tabla
1
2
3
4
5
6
Sub Obtener_TablaActualizada()
Dim tempDetalle As DataTable
tempDetalle = ViewState("detalle")
gvDetallePedido.DataSource = tempDetalle
gvDetallePedido.DataBind()
End Sub
pero cuando lo ingreso dentro del RowDataBound el for entra en un ciclo de bucle, asique no se como solucionar mi problema, alguien tiene alguna idea?, desde ya muchisimas gracias por sus tiempos!
Valora esta pregunta


0