Click here to Skip to main content
15,880,503 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have data in in Data table Single column givem below. how can i sort?

13.0
12.2
12.1
12.0
11.2
11.1
11.0
10.3
10.2
10.1
10.0

I want above data like below

13.0
12.0
12.1
12.2
11.0
11.1
11.2
10.0
10.1
10.2
10.3
Posted
Comments
DamithSL 13-Jun-14 5:43am    
what is the column data type? and which .net framework version you are using?
Member 10453691 13-Jun-14 5:46am    
column data type is decimal and Framework 3.5
Thanks7872 13-Jun-14 5:43am    
On what basis you sort this? Why 13.0 is at first place?
Member 10453691 13-Jun-14 5:47am    
Because i have need to print data like these. i already short datatable but it give value about that i tell u. but i want to short these kind of.
Nandakishore G N 13-Jun-14 7:22am    
Paste the codebehind what you have done?

Try this:
datatable.DefaultView.Sort = "columnname DESC"; 

Refer: Datatable+sorting+[^]
 
Share this answer
 
v2
Comments
Member 10453691 13-Jun-14 5:47am    
i already applied
try like below
C#
DataView dv = dt.DefaultView;
dv.Sort = "ColumnName desc";
DataTable sortedDT = dv.ToTable();


you can Sorting with DataView (LINQ to DataSet)[^]
Sample code:
C#
DataTable orders = dataSet.Tables["SalesOrderHeader"];

EnumerableRowCollection<DataRow> query = from order in orders.AsEnumerable()
                                         orderby order.Field<decimal>("TotalDue") 
                                         select order;

DataView view = query.AsDataView();

bindingSource1.DataSource = view;
 
Share this answer
 
v2
Comments
Member 10453691 13-Jun-14 5:47am    
i already applied
DamithSL 13-Jun-14 5:51am    
check my updated answer
Member 10453691 13-Jun-14 6:29am    
not working

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