Click here to Skip to main content
15,906,329 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have parent Panel control which include CheckBoxes.
If I check one of them ChechBox another child Panel opens and it also include chechboxes.
My requirement is I have to find child checkboxes using FindControl
How can I do this.

Please anyone Help Me.

Thanks
Posted

Are you looking for this
C#
CheckBox chk1= this.FindControl("parentPanel").FindControl("childPanle").FindControl("checkBox1") as CheckBox;
 
Share this answer
 
childpanel.findcontrol("checkbox in child panel");
 
Share this answer
 
Hi,

Try this-

HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:panel id="Panel1" runat="server" xmlns:asp="#unknown">
        <asp:checkbox id="CheckBox1" runat="server" checked="true" />
        <asp:panel id="Panel2" runat="server">
            <asp:checkbox id="CheckBox2" runat="server" />
            <asp:checkbox id="CheckBox3" runat="server" />
        </asp:panel>
    </asp:panel>
    </form>
</body>
</html>


C#
protected void Page_Load(object sender, EventArgs e)
{
    if (((CheckBox)Panel1.FindControl("CheckBox1")).Checked)
    {
        foreach (Control ctrl in ((Panel)Panel1.FindControl("Panel2")).Controls)
        {
            if (ctrl.GetType() == typeof(CheckBox))
            {
                //your checkbox
            }
        }
    }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900