Solved

Read Values from Nested ListView

Posted on 2011-09-24
2
396 Views
Last Modified: 2012-06-21
I am using a nested ListView as a data entry form and have everything bound exactly right.  The basic format is:
<ListView1>
<Item Template>
<ListView2>
<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
                    arrSpecies.Add(v)
                End If
            Next
        Next
Thanks for your help!
0
Comment
Question by:AJ0718
2 Comments
 
LVL 12

Accepted Solution

by:
jagssidurala earned 500 total points
ID: 36594419
Change your code like below,
i have higjlighted the code change

Dim arrSpecies As New ArrayList()
        For Each item As ListViewItem In ListView1.Items
            Dim ListView2 As ListView = DirectCast(item.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
                    arrSpecies.Add(v)
                End If
            Next
        Next
0
 

Author Closing Comment

by:AJ0718
ID: 36595064
Fantastic!  Thanks so much.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

947 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now