dynamic datatable sorting in ascending or descending

This cannot be done with the original data table. However you can create a new, sorted one:

DataView view = date.DefaultView;
view.Sort = "date1 ASC";
DataTable sortedDate = view.ToTable();

You can use DataTable.Select(filterExpression, sortExpression) method.

Gets an array of all DataRow objects that match the filter criteria, in the specified sort order.

date.Select("", "YourColumn ASC");

or

date.Select("", "YourColumn DESC");

As an alternative, you can use DataView like;

DataView view = date.DefaultView;
view.Sort = "YourColumn ASC";
DataTable dt = view.ToTable();

Tags:

C#

Asp.Net