Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to Sort Decimal Place number in Datatable Or Dataview.



i have data like below


13.5
13.9
13.1
13.2

i want to Sort data after decimal places in Datatable or Dataview. Please give me solution for that.
Posted
Comments
ZurdoDev 16-Jun-14 8:39am    
Where are you stuck?
Nandakishore G N 16-Jun-14 10:42am    
What you have you done paste it. so that anyone can help you to sort the problem. Don't just ask I need solution? try and show what you have done and I'm sure everyone will try to help you to sort the problem.

try these snippet in your code

DataView dv = dt.DefaultView;
dv.Sort = "columnname desc";
DataTable dts = dv.ToTable();

See here: http://stackoverflow.com/questions/89987/how-to-naturally-sort-a-dataview-with-something-like-icomparable[^]

Or better, don't put strings into your data when you want numbers: use numeric fields instead. They sort correctly and normally.
 
Share this answer
 
Comments
Member 10453691 16-Jun-14 8:42am    
i still not understand stand
1. Create a clone of the data in the above table that you have.
2. Specify the Data Type in clone table, for the sort column as needed. Eg. System.Decimal for decimal column.
3. Import each row from original table to clone table.
4. Commit the changes in clone table.
5. Create a DataView on clone table.
6. Specify the sort column and sort order for the DataView.
7. Bind DataView to GridView.



C#
DataTable dtMarks1 = dtMarks.Clone();
            dtMarks1.Columns["Total"].DataType = Type.GetType("System.Decimal");

            foreach (DataRow dr in dtMarks.Rows)
            {
                dtMarks1.ImportRow(dr);
            }
            dtMarks1.AcceptChanges();


            DataView dv = dtMarks1.DefaultView;
            dv.Sort = "Total DESC";

            GridView1.DataSource = dv;
            GridView1.DataBind();
 
Share this answer
 
v3
Comments
Member 10453691 16-Jun-14 8:41am    
in above how can i sort after decimal place value.

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