Click here to Skip to main content
15,065,328 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
SQL
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
XML
<asp:Label ID="txtdate" runat="server" Text='<%# bind("Date") %>' CssClass="labelstyle" >
Posted
Updated 1-Oct-12 19:30pm
v5

1 solution

Since, your date column is of type varchar, you face this issue.

Try:
SQL
ORDER BY CONVERT(DATETIME, ts.Date, 103) DESC

in your query and see.

UPDATE:
Was just confirming my answer, looks good: Refer[^]
   
v2

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