Check CheckBox inside inner Repeater from outer Repeater checked in Asp.Net

749 Views Asked by At

There are two CheckBoxes one is in outer Repeater and other is inside inner Repeater.

I would like to automatically check CheckBox of inner Repeater when checked the outer Repeater's CheckBox.

HTML Markup:

<asp:Repeater ID="repOuter" runat="server">
    <ItemTemplate>
        <asp:CheckBox ID="chkOuter" runat="server" 
             OnCheckedChanged="chkOuter_CheckedChanged" />

        <asp:Repeater ID="repInner" runat="server">
            <ItemTemplate>
                <asp:CheckBox ID="chkInner" runat="server" />
            </ItemTemplate>
        </asp:Repeater>

    </ItemTemplate>
</asp:Repeater>

Code-Behind

protected void chkOuter_CheckedChanged(object sender, EventArgs e)
{
    // can't have access to inner CheckBox placed inside Inner Repeater
    CheckBox innerCheckBox; // how?

    innerCheckBox.Checked = true; // want to check it
}
1

There are 1 best solutions below

0
On BEST ANSWER

You can try this(though untested).

CheckBox chkOuter = (sender as CheckBox);
RepeaterItem item = (RepeaterItem)chkOuter.NamingContainer;   
Repeater rp = item.FindControl("repInner") as Repeater;
foreach (RepeaterItem item in rp.Items)
{    
    (item.FindControl("chkInner") as CheckBox).Checked = chkOuter.Checked;
}