Monday, August 17, 2009

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

C#



protected void Button1_Click(object sender, EventArgs e)

{

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

select ctr;

}



VB.NET


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

No comments:

Post a Comment