LINQ - The Uber FindControl
With a simple extension method to ControlCollection to flatten the control tree you can use LINQ to query the control tree:
public static class PageExtensions { public static IEnumerable<Control> All(this ControlCollection controls) { foreach (Control control in controls) { foreach (Control grandChild in control.Controls.All()) yield return grandChild; yield return control; } } }
Now I can do things like this:
// get the first empty textbox TextBox firstEmpty = accountDetails.Controls .All() .OfType<TextBox>() .Where(tb => tb.Text.Trim().Length == 0) .FirstOrDefault(); // and focus it if (firstEmpty != null) firstEmpty.Focus();
Pretty cool! I can do all sorts of querying of the control tree now. LINQ you are my h
Also see: Infrequent blogging
Also see: Alexbarn Leaves Microsoft…ARGH!
Also see: Eriskay: a Programming Language Based on Game Semantics
Also see: Java Concurrency, another series on its issues
Also see: Important changes to the BASE element for IE 7
Also see: Snippet Compiler update
Also see: From C# to Java: Part 5
ero.http://weblogs.asp.net/dfindley/archive/2007/06/29/linq-the-uber-findcontrol.aspx
