Click here to Skip to main content
15,889,266 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Ho to sort individually multiple columns in datatable.
Posted
Updated 1-Jun-17 13:38pm

Hi,

you can try this one.

C#
DataTable dt = new DataTable();
            dt.Columns.Add("Value1", typeof(string));
            dt.Columns.Add("Value2", typeof(string));
 
            dt.Rows.Add("viprat", 7);
            dt.Rows.Add("Test2", 5);
            dt.Rows.Add("abcd", 2);
 
            DataView dv = new DataView(dt);
            dv.Sort = "Value1 ASC, Value2 DESC";
 
Share this answer
 
v2
Comments
manak chand 1-Nov-12 8:25am    
sorting should be like
value1 asc
and
value2 desc
VIPR@T 1-Nov-12 8:29am    
see the updated solution

dv.Sort = "Value1 ASC, Value2 DESC";
SQL
Select *from Employees order by EmpID,EmpName


Put order by clause and write all columnNames seperated by comma.
 
Share this answer
 
Comments
manak chand 1-Nov-12 8:25am    
i want to do it in datatable
Sanjay K. Gupta 1-Nov-12 8:31am    
dt.DefaultView.Sort = "EmpID,EmpName Desc";//dt is your datable instance

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900