Click here to Skip to main content
12,404,895 members (70,092 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VB VB.NET
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 20-Mar-13 1:32am
Updated 20-Mar-13 1:33am
v2
Comments
ryanb31 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.
   
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
   
Probably the sorting operation is done by javascript (client-side), right ? This way your code is sorting the date column as string.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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:
SELECT Field1, Field2, ...
FROM YourDataBase
ORDER BY StartDate, EndDate

Date format has nothing to do with it.
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 11 Aug 2015
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100