ControlHelper.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. namespace GreenTree.Nachtragsmanagement.Web.Extensions
  7. {
  8. public static class ControlHelper
  9. {
  10. public static Control[] GetAllSubControlsOfTypes(this Control control, params Type[] types)
  11. {
  12. var result = new List<Control>();
  13. GetSubControls(control, result, types);
  14. return result.ToArray();
  15. }
  16. private static void GetSubControls(Control parent, List<Control> result, Type[] types)
  17. {
  18. if (parent == null) return;
  19. foreach (Control subControl in parent.Controls)
  20. {
  21. if (subControl.Controls.Count > 0)
  22. GetSubControls(subControl, result, types);
  23. foreach (var type in types)
  24. {
  25. if (subControl.GetType() == type)
  26. {
  27. result.Add(subControl);
  28. break;
  29. }
  30. }
  31. }
  32. }
  33. }
  34. }