Wednesday, September 7, 2011

sort a DataTable to another DataTable

public void resortDataTable(string sortBy)

{

   if (!sortBy.IsNullOrEmpty())

   {

      IEnumerable<DataRow> query = from row in Whatever.AsEnumerable()

         orderby row.Field<object>(sortBy)

         select row;

      DataTable boundTable = query.CopyToDataTable<DataRow>();

      Whatever = boundTable;

   }

}

No comments:

Post a Comment