[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2057
  • Last Modified:

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

0
mugsey
Asked:
mugsey
  • 2
1 Solution
 
tovvenkiCommented:
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

0
 
mugseyAuthor Commented:
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.
0
 
tovvenkiCommented:
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
0
 
MogalManicCommented:
I never heard of FINDCONTROLOFTYPE either, but I have written many times a recursive FindControl() that searches the pages control hierarchy for a deeply nested control.

Here is an article that describes the process:

http://leadingthenextinquisition.wordpress.com/2006/08/07/c-custom-findcontrol-implementation/
http://leadingthenextinquisition.wordpress.com/2006/08/07/custom-findcontrol-implementation-c-part-ii/ 
0

Featured Post

Technology Partners: 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!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now