I have a Gridview where I have several columns, the last one has numeric values, my gridiview poses a checkbox, what I want to do is to do a check in one or more rows, add the amounts to a texbox, try several ways as you will see low but I could not get it, I hope you can help me help
Button code:
Protected Sub BtnAplica_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnAplica.Click
Dim resultado As String
Dim resultado2 As String
Dim Seleccion As Boolean = False
Dim sum As Double = 0
For Each RW As GridViewRow In Gvcobranzas.Rows
If CType(RW.Cells(2).FindControl("CheckBox1"), CheckBox).Checked Then
If GM.ValidaCliente(TxtBuscarCli.Text) = False Then
ElseIf GM.ValidaNPago(TxtNuPago.Text) = False Then
resultado = GM.IsnPago(TxtBuscarCli.Text, dlBnaco.SelectedValue, TxtPagoTotal.Text, TxtNuPago.Text, TxtFePago.Text, TxtFeReg.Text)
Seleccion = True
With lberror1
.Visible = True
.Text = resultado
End With
Limpiar()
CargaGridClientes()
CargaGridnotascreditos()
Else
With lberror1
.Visible = True
.Text = "Ya existe un numero de pago, no se permiten duplicados"
End With
Limpiar()
CargaGridClientes()
CargaGridnotascreditos()
End If
Else
With lberror1
.Visible = True
.Text = "Favor de seleccionar las factura a pagar"
End With
Limpiar()
End If
Next
For Each fila As GridViewRow In GvNotasCredito2.Rows
Dim NCF As String = fila.Cells(1).Text
Dim monto As Double = fila.Cells(2).Text
resultado2 = GM.InsNotaC(NCF, TxtNuPago.Text, monto)
With lberror0
.Visible = True
.Text = resultado2
End With
Next
CargaGridClientes()
CargaGridnotascreditos()
End Sub
I tried to do this method but it does not work for me
Private Sub SumOpcion2()
Dim total As Decimal = 0
For Each row As GridViewRow In Gvcobranzas.Rows
If CType(row.Cells(0).FindControl("CheckBox1"), CheckBox).Checked Then
Dim x As Decimal = 0
If Decimal.TryParse(row.Cells(0).Text, x) Then
total += x
End If
End If
Next
TxtMonto.Text = total
End Sub
even try the Changed CheckBox event but not
Protected Sub CheckBox1_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
For Record As Integer = 0 To (Gvcobranzas.Rows.Count - 1)
CType(Gvcobranzas.Rows(Record).FindControl("CheckBox1"), CheckBox).Checked = CType(Gvcobranzas.HeaderRow.FindControl("CheckBox1"), CheckBox).Checked
Next
Dim total As Decimal = 0
For Each row As GridViewRow In Gvcobranzas.Rows
If CType(row.Cells(0).FindControl("CheckBox1"), CheckBox).Checked Then
Dim x As Decimal = 0
If Decimal.TryParse(row.Cells(0).Text, x) Then
total += x
End If
End If
Next
TxtMonto.Text = total
End Sub