how to count specific controls in a container c#

49

how to count specific controls in a container c# -

protected void btnGetCount_Click(object sender, EventArgs e)
    {
        Control control = new Control();

        int countCB = 0;
        int countTB = 0;
        foreach (Control c in this.Controls)
        {
            if (control.GetType() == typeof(CheckBox))
            {
                countCB++;
            }
            else if (control is TextBox)
            {
                countTB++;
            }
        }

        Response.Write("No of TextBoxes: " + countTB);
        Response.Write("<br>");
        Response.Write("No of CheckBoxes: " + countCB);
    }

Comments

Submit
0 Comments