Read Values from Nested ListView
Posted on 2011-09-24
I am using a nested ListView as a data entry form and have everything bound exactly right. The basic format is:
<some controls in ListView2 with values from database and user-entered>
The problem comes on submit when I am trying to get values from the form. I am looping through both listviews but debug shows I am not finding ListView2 and consequently none of its controls. Can someone please tell me where I am going wrong?
Dim arrSpecies As New ArrayList()
For Each item As ListViewItem In ListView1.Items
Dim ListView2 As ListView = DirectCast(ListView1.FindControl("ListView2"), ListView)
For Each row As ListViewItem In ListView2.Items
Dim hfSpeciesID As HiddenField = DirectCast(row.FindControl("hfSpeciesID"), HiddenField)
Dim SpeciesID As String = hfSpeciesID.Value
Dim tbHowMany As TextBox = DirectCast(row.FindControl("tbHowMany"), TextBox)
Dim Individuals As String = tbHowMany.Text
If Individuals <> "" Then
Dim v As String = SpeciesID & "-" & Individuals
Thanks for your help!