Attention: We are retiring the ASP.NET Community Blogs. Learn more >

Sorting dataview on multiple columns

Hi,

 

Yesterday I was wondering through the msdn and found an interesting stuff that I did not knew before. I have worked with Dataview many a times and know how to work with it sort property. The sort property takes a string. The string is the columnname on which the dataview will be sorted.

 

What I did not knew was that the dataview can be sorted on multiple columns using the sort property. For sorting the columns on multiple columns we need to separate the columns with a comma. To define the sort direction we can use ASC or DESC after the column name.

Here is an example on how to sort a dataview in multiple columns 
// Get the DefaultViewManager of a DataTable.
DataView view = DataTable1.DefaultView;
// By default, the first column sorted ascending.
view.Sort = "LastName ASC, FirstName ASC, Age DESC";
Vikram

 

2 Comments

Comments have been disabled for this content.