Fetching all controls on a page ordered by their ID

Here's a simple to way to fetch all the controls on an ASP.NET page ordered by their ID's


    protected void Button1_Click(object sender, EventArgs e)


        var ctrl = from ctr in this.Controls.Cast<Control>().OrderBy(c => c.ID)

                   select ctr;     



Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)

    Dim ctrl = _

     From ctr In Me.Controls.Cast(Of Control)().OrderBy(Function(c) c.ID) _

     Select ctr

End Sub

About The Author

Suprotim Agarwal
Suprotim Agarwal, Developer Technologies MVP (Microsoft Most Valuable Professional) is the founder and contributor for DevCurry, DotNetCurry and SQLServerCurry. He is the Chief Editor of a Developer Magazine called DNC Magazine. He has also authored two Books - 51 Recipes using jQuery with ASP.NET Controls. and The Absolutely Awesome jQuery CookBook.

Follow him on twitter @suprotimagarwal.

No comments: