Get all Checkbox controls in a Page or a Container

Posted by Unknown On Tuesday, December 30, 2014 0 comments

Following is a way to get all checkbox controls in a Panel named panelMainContent.

C#

private void GetCheckBoxControls()
{
         LoopControls(panMainContent.Controls);
}

private void LoopControls(controlCollection)
{         
        foreach (Control control in controlCollection)
        {
            if (control is CheckBox)
            {
                var menuControl = (CheckBox)control;
                if (menuControl.Checked)
                {
                     //do something
                }
            }

            if (control.Controls != null)
            {
                LoopControls(control.Controls);
            }
        }
}

0 comments:

Post a Comment