Get the value of one column of a GridView for each ROW

1

I'm trying to get the value of a column of a GridView because I need to validate if a field is empty a checkbox equals Enable=True

Protected Sub VALIDAR_CheckBox()

    Dim nrAs Integer
    nr= ResultadosBusqueda.Rows.Count

    Dim i As Integer

    For i = 0 To nr- 1
        Me.GridView1.Rows(i).FindControl("Fecha")


    Next

End Sub
    
asked by ARR 31.01.2018 в 23:33
source

1 answer

1

With a GridView do the following:

Protected Sub VALIDAR_CheckBox()

    Dim nr As Integer
    nr= ResultadosBusqueda.Rows.Count

    Dim i As Integer

    For i = 0 To nr- 1
        'En Cell(0), cambia el número cero por el número de la columna
        If GridView1.Rows(i).Cells(0).Text = "" Then
             'Acciones
        End If
    Next
End Sub

Now, in case you had many columns and / or did not know the column number, you can store the column number in a variable.

Protected Sub VALIDAR_CheckBox()

    Dim nr As Integer
    nr= ResultadosBusqueda.Rows.Count

    'Declaras la variable
    Dim NumeroDeColumna As Integer

    'Recorres el Gridview para obtener el número de la columna que se llame NombreDeUsuario
    For j As Integer = 0 To GridView1.Columns.Count - 1
        If GridView1.Columns.Item(j).HeaderText = "NombreDeUsuario" Then
            NumeroDeColumna = j
            Exit For
        End If
    Next

    Dim i As Integer

    For i = 0 To nr- 1
        'Utilizas la variable NumeroDeColumna
        If GridView1.Rows(i).Cells(NumeroDeColumna).Text = "" Then
             'Acciones
        End If
    Next
End Sub
    
answered by 20.12.2018 / 04:05
source