Solved

Read Values from Nested ListView

Posted on 2011-09-24
2
395 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

706 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

18 Experts available now in Live!

Get 1:1 Help Now