Solved

Read Values from Nested ListView

Posted on 2011-09-24
2
403 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…

734 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