ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

FindControlsByType

Used in conjunction with GetChildren(), it will return a list of T from a list of children of a control. Get Children is located at: http://www.extensionmethod.net/Details.aspx?ID=309

Source

public static List<T> FindControlsByType<T>(this Control ctrl)
{
  return ctrl.GetChildren().OfType<T>().ToList();
}

Example

List<TextBox> textboxes = Control.FindControlsByType<TextBox>();

Author: Ryan Helms

Submitted on: 18 jul. 2010

Language: C#

Type: System.Control

Views: 4979