ASP.NET Recursively Find Child Controls by Type

        protected ArrayList getChildControlsByType(Control c, string sType)
        {
            ArrayList controls = new ArrayList();
            if (c != null)
            {
                if (c.GetType().ToString() == sType)
                {
                    controls.Add(c);
                }
                else
                {
                    foreach (Control c1 in c.Controls)
                    {
                        controls.AddRange(getChildControlsByType(c1, sType));
                    }
                }
            }
            return controls;
        }

Leave a Reply

Your email address will not be published. Required fields are marked *