Link to home
Start Free TrialLog in
Avatar of mugsey
mugseyFlag for United Kingdom of Great Britain and Northern Ireland

asked on

How to get reference to nested listview using findcontrol method

I have two listview controls nested

An outer listview and an inner listview

The innerlistview is a set of checkboxes that are populated from a database

I want code that uses the findcontrol method to get a reference to the inner listview so I can loop through all the checkboxes generated from the database and set them to false.

The markup for the controls is below
<asp:ListView ID="outerListView" runat="server" DataKeyNames="Id" OnItemDataBound="outerListView_ItemDataBound">
                        <LayoutTemplate> 
                            <asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder>
                        </LayoutTemplate>
                        <ItemTemplate>
                            <fieldset>
                                <legend>
                                    <%#Eval("Description") %></legend>
                                <!-- inner listview -->
                                <asp:ListView ID="innerListView" runat="server" DataKeyNames="Id" OnItemDataBound="innerListView_ItemDataBound">
                                    <LayoutTemplate>
                                        <asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder>
                                    </LayoutTemplate>
                                    <ItemTemplate>
                                        <asp:CheckBox ID="_checkBoxField" runat="server" Text='<%#Eval("Description") %>'
                                            OnCheckedChanged="_checkBoxField_CheckedChanged" />
                                        <br />
                                    </ItemTemplate>       
                                </asp:ListView>
                                <!-- innerlistview -->
                            </fieldset>
                        </ItemTemplate>                     
                    </asp:ListView>

Open in new window

Avatar of tovvenki
tovvenki

Hi,
A reference to the parent listview is passed to the itemdatabound you can use it to find the child listview

protected void outerListView_DataBound(object sender, EventArgs e)  
{  
    ListView outerLstVw = (ListView)sender;  
    Listview innerLstVw = (ListView)outerLstVw.FindControl ("innerListView");
}

for more info you can also refer to the discussion here
http://forums.asp.net/t/1465507.aspx

I hope that this helps you

Thanks and regards,
Venki

Avatar of mugsey

ASKER

OK thanks.   However can I do the same thing you suggested but use the FINDCONTROLOFTYPE method?

As the html generated ID of each checkbox will be different.
hey,
Where did you got the method FINDCONTROLOFTYPE?
I have not used it before need to check that.
Sorry could not help you on this.

Thanks and regards,
Venki
ASKER CERTIFIED SOLUTION
Avatar of MogalManic
MogalManic
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial