nested listview how to iterate through child listview control

Posted on 2008-11-06
Last Modified: 2012-05-05
I have nested listview (see below)

How can I iterate through child listview ?

I am using
    ListView ChildListView = (ListView)parentListView.FindControl("childListView");   //THIS IS ALWAYS NULL!

    foreach (ListViewDataItem item in ChildListView.Items)

I cannot get a reference to the child listview - how can I solve this?

<asp:ListView ID="parentListView" runat="server"  


                <asp:PlaceHolder ID="itemPlaceholder" runat="server">                   </asp:PlaceHolder>



                <!-- title goes here -->

                <asp:ListView ID="childListView" runat="server" 


                                <asp:PlaceHolder ID="itemPlaceholder" .....




Open in new window

Question by:mugsey
    LVL 13

    Expert Comment

    on which event you trying to get reference below
    ListView ChildListView = (ListView)parentListView.FindControl("childListView");  

    Author Comment

    I am not using any of the listview events - you see I am inserting a new entity into the database

    So I have an addbutton event

    Then I want to iterate through the child listview
    LVL 27

    Accepted Solution

    Hello mugsey,

    Lets assume that your parentListView has several items.
    Each one of them has a childLIstView. Which one of these childListViews are you referring to?

    Somehow you have to use the Selected item in your code

    My snippet might give you an idea


    ListViewDataItem ChildDataItem = parentListView.Items[parentListView.SelectedIndex].DataItem
    //This ChildDataItem probably will lead you to your child list view

    Open in new window


    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK ( for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    This video discusses moving either the default database or any database to a new volume.
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now