nested listview how to iterate through child listview control

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"  
        <LayoutTemplate>
                <asp:PlaceHolder ID="itemPlaceholder" runat="server">                   </asp:PlaceHolder>
        </LayoutTemplate>
        <ItemTemplate>
                <!-- title goes here -->
                <asp:ListView ID="childListView" runat="server" 
                        <LayoutTemplate>
                                <asp:PlaceHolder ID="itemPlaceholder" .....
                                        </LayoutTemplate>
                                    <ItemTemplate>
                                    </ItemTemplate>

Open in new window

mugseyAsked:
Who is Participating?
 
DabasConnect With a Mentor Commented:
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

Regards,

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

Open in new window

0
 
sm394Commented:
on which event you trying to get reference below
ListView ChildListView = (ListView)parentListView.FindControl("childListView");  
0
 
mugseyAuthor Commented:
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.