I am trying to add the templateFields‘ values of my gridview into a List(Of String). Those templateFields consist of 2 Labels. What I am trying to achieve is
-
To be able to loop through every row of the
GridView, getting the repetitive templateField values. -
Store the row’s
TemplateFields1values in a string. -
Add that string into a list of strings.
Here’s my code:
For Each row As GridViewRow In GridView1.Rows`
Dim stri As String
Dim ttt As Label = DirectCast(row.FindControl("Title"), Label)
Dim desc As Label = DirectCast(row.FindControl("lblDescription"), Label)
stri = ttt.Text.ToString & desc.Text.ToString
Dim list As New List(Of String)
While (stri <> Nothing)
list.Add(stri) ' Add every new string in a new index of the list
End While
Next
So in the while loop, take stri store it in list(0) and then continue the for loop, get the next stri and store it in a new index of list(1) while keeping list(0) and so on until all templateField stri is completed.
Any thoughts or suggestions ?
You must create the list outside the loop. I’d also replace the
Whileloop with anIfstatement: