Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
Hiiii,
I have gridview,in which one column is for date..i m sorting gridview by date (descending).But the problem is it sorts date by day only instead i want date sorted by day and month.
for example,query which i have written gives me output like...
DATE
31/9/2012
31/8/2012
31/7/2012
31/6/2012
30/9/2012
30/6/2012
28/9/2012
28/8/2012
Instead of i want
31/9/2012
30/9/2012
29/9/2012
28/9/2012
31/8/2012
28/8/2012
31/7/2012
30/6/2012
Help me plzz.
I have written following code in my .aspx.cs file.
userlist_data.SelectCommand = "SELECT CONVERT(VARCHAR(10), ts.Date, 103) AS Date, ts.CLTId, ts.JobId, ts.FromTime, ts.ToTime, ts.StaffCode, ts.TSId, ts.TotalTime, j.JobName, c.StaffName, ts.OpeAmt, ts.Narration, j.MJobid, dbo.JobName_Master.MJobName, dbo.Client_Master.ClientName "
               + " FROM TimeSheet_Table AS ts INNER JOIN Job_Master AS j ON j.JobId = ts.JobId INNER JOIN Staff_Master AS c ON ts.StaffCode = c.StaffCode INNER JOIN JobName_Master ON j.MJobid = dbo.JobName_Master.MJobId INNER JOIN Client_Master ON ts.CLTId = dbo.Client_Master.CLTId WHERE ts.CompId = '" + ViewState["compid"] + "' and ts.status='Approved' and j.jobapprover=" + apprid + " order by Date DESC";
 
and in .aspx
<asp:Label ID="txtdate" runat="server" Text='<%# bind("Date") %>' CssClass="labelstyle" >
Posted 1-Oct-12 19:06pm
Edited 1-Oct-12 19:30pm
ridoy51.8K
v5

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Since, your date column is of type varchar, you face this issue.
 
Try:
ORDER BY CONVERT(DATETIME, ts.Date, 103) DESC
in your query and see.
 
UPDATE:
Was just confirming my answer, looks good: Refer[^]
  Permalink  
v2

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



Advertise | Privacy | Mobile
Web03 | 2.8.140926.1 | Last Updated 2 Oct 2012
Copyright © CodeProject, 1999-2014
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