Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Guys , i was spent more on these requirement, but i doesn't get the answer.

I Have a DataGrid with columns Like BENCHMARKNO ,BENCHMARKNAME ,CLIENTCODE ,NOFILES ,REFERENCENO ,NORESOURCES ,STARTDATE, FINISHDATE, AUTHORIZEDBY.


Except STARTDATE and FINISHDATE Columns , Remaining all columns are sorted successfully.


I am getting the Date Formats like these


01-March-2010

05-February-2009

13-January-2009

07-July-2013


I Want like these :

13-January-2009
05-February-2009

01-March-2010

07-July-2013


Please any one help me.
Posted
Updated 20-Mar-13 1:33am
v2
Comments
ZurdoDev 20-Mar-13 9:02am    
Please post the relevant code for the sorting and your aspx columns of the datagrid.
Prasad Khandekar 20-Mar-13 17:22pm    
Check whether startdate & finishdate columns in database are of correct data type and You have also specified the correct data type of respective columns in DataGridView. The error you are facing mostly occurs because of incorrect data type or a string value in column.
José Amílcar Casimiro 20-Mar-13 17:23pm    
You get this order result, because the ordering of dates is being done by string type.
Sort for a different data type, or format the date in a way that the ordering is correct.
CH Guravaiah 21-Mar-13 2:48am    
Starttime and finishtime are DateTime Datatype
José Amílcar Casimiro 21-Mar-13 5:55am    
Probably the sorting operation is done by javascript (client-side), right ? This way your code is sorting the date column as string.

I'm not sure what about you're asking for...

You can sort data in 2 methods:
1) using DataGridView properties: Sorting Data in WinForms DataGridView Control[^]
or
2) sorting its datasource:
SQL
SELECT Field1, Field2, ...
FROM YourDataBase
ORDER BY StartDate, EndDate


Date format has nothing to do with it.
 
Share this answer
 
I did a lot of looking and then used something really easy. I added a hidden column, and put in a string date in the following format:
File.GetLastWriteTime(fl).ToString("yyyyMMddhhmm") and sorted the hidden column.
While I am using a file time there is no reason that any date/time should not work.
 
Share this answer
 

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