Home  »  Code Snippets  »  C#.Net  »

Sorting Data in C# DataTable

 Posted By : Manoranjan SahooPosted Date : 04/08/2014 04:47:43 PM Category : C#.Net Points : 2

To do the sorting in datatable follow below steps. For example consider below table.

Now, the table needs to be sorted in descending order, based on Price column. Below are the steps to do the same:

1. Create a DataView on DataTable.
2. Specify the sort column and sort order for the  DataView.
3. Convert DataView to DataTable

//DataTable dt=new DataTable(); this is a new data table. but you can take your own datatable
// Create DataView
DataView view = new DataView(dt);

// Sort by price column in descending order
view.Sort = "Price DESC";

Responses
No responses found for this thread. Be the first to respond this thread.
Post Reply
Login to post Response.