Finding All Controls In ASP.NET Page

When you work with ASP.NET page, you might need to enumerate all controls of a specific type, i.e. text boxes, dropdown list, or table cells. All these controls derive from System.Web.UI.Control class.
To find all controls you need to iterate them recursively from the top one, i.e. Page, or any element that is located on a page (panel, table, etc.). One of the solution is to write an extension method like this.

Also you can use a generic version.

When I need to find all table cells with a specific ID, I can write the following LINQ query:

In C# 6.0 and later you can use Elvis operator in Where clause.

Converting List To DataTable

In my previous post SqlBulkCopy I wrote about how to load data from .NET code into SQL Server database using efficient BULK INSERT command. This class needs a DataTable or IDataReader instance as a source. I’ve collected a couple of examples how to convert List to DataTable.

1. Variation of Marc Gravell solution.

2. Solution created by Jennifer Hubbard, Bill Wagner, etc.
Source: How to: Implement CopyToDataTable<T> Where the Generic Type T Is Not a DataRow