internal static DataTable SortDataTable(DataTable unsortedData, OrderByClause orderBy) { bool shouldSort = (orderBy != null && orderBy.Count > 0); if (!shouldSort) return unsortedData; DataRow[] sortedRows = unsortedData.Select(null, orderBy.GetDataViewSortExpression()); DataTable sortedData = unsortedData.Clone(); sortedData.BeginLoadData(); foreach (DataRow row in sortedRows) sortedData.ImportRow(row); sortedData.EndLoadData(); return sortedData; }