How to get data when you go through a GridView For Each vb.net asp.net

1

I want to get the data that I'm going through in a GridView

For Each Fila As GridViewRow In GCURSO.Rows
     ceEvaluacion.CursoAlumno = Fila.Cells(0).ToString
Next

But when using Fila.Cells(0).ToString I do not get the data. Thanks.

    
asked by Jonathan Valle 17.03.2018 в 16:25
source

3 answers

1

I have found a solution to my problem, I share it and I hope it will be useful for you:

Since the value I needed to capture was in a hidden column and strVariable = Row.Cells (1) .Text.ToString only captures values of columns that are displayed. Add the DataKeyNames="Column Id" property to the Grid and in For Each I capture the value strVariable = Me.GridView.DataKeys (Row.RowIndex) .Value

It stays like this

For Each Row As GridViewRow In GCURSO.Rows

strVariable = Me.GridView.DataKeys (Row.RowIndex) .Value

next

Greetings and Thanks

    
answered by 17.03.2018 в 18:48
0

You should do it this way:

 For Each Fila As DataGridViewRow In GCURSO.Rows
     ceEvaluacion.CursoAlumno = Fila.Cells(0).Value
Next

You are going through a GridViewRow and you must be DataGridViewRow plus you are missing the .Value of the cell. Fila.Cells(0).Value

    
answered by 17.03.2018 в 16:49
0
For Each Fila  In GCURSO.Rows.Cast(Of DataGridViewRow)()
     ceEvaluacion.CursoAlumno = Fila.Cells("nombredecolumna").Value.ToString()
Next

Although I do not understand why you go through all the rows and assign your first column to only one variable, you are only saving the last row because the previous ones lose.

I recommend that instead of directly using the column number, refer to the name of the column, so, if you add another column afterwards at the beginning, you will not get an error.

    
answered by 18.03.2018 в 21:19