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


Wraps the usage of some DataTable.DefaultView properties to return sorted rows filtered on a custom filterexpression. For documentation on what to put in the whereExpression and the orderByExpression, refer to the MSDN documentation of DataTable.DefaultView.RowFilter and DataTable.DefaultView.Sort.


public static DataTable SelectRows(this DataTable dt, string whereExpression, string orderByExpression)
	dt.DefaultView.RowFilter = whereExpression;
	dt.DefaultView.Sort = orderByExpression;
	return dt.DefaultView.ToTable();


DataTable selection = dt.SelectRows("ID > 10", "Name");

Author: Dan Pettersson

Submitted on: 21 dec 2009

Language: C#

Type: System.Data.DataTable

Views: 6578