This is a migrated thread and some comments may be shown as answers.

[Solved] sorting column with Date/Time data

2 Answers 316 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jonathan
Top achievements
Rank 1
Jonathan asked on 11 Jun 2008, 09:04 PM
I have a RadGrid in which the structure is built in the code-behind and the data sources are ObjectDataSources in the html. Everything works well except I'm trying to sort a column containing a Date/Time and while it sorts it is not sorting as expected. So, I have the following in the code-behind:

GridSortExpression

sortExp = new GridSortExpression();
sortExp.FieldName =
"ScheduledArrivalTime";
sortExp.SortOrder =
GridSortOrder.Ascending;
RadGrid1.MasterTableView.SortExpressions.AddSortExpression(sortExp);

boundColumn =
new GridDateTimeColumn();
RadGrid1.MasterTableView.Columns.Add(boundColumn);
boundColumn.DataField =
"ScheduledArrivalTime";
boundColumn.HeaderText =
"Scheduled Arrival Time";

It appears it is sorting on the column but numerically, not by date. For example, these 3 dates, 6/6/2008, 6/10/2008, 6/11/2008, sort ascending as 6/10/2008, 6/11/2008, 6/6/2008.

What's wrong in the code above? Do I need to use the DataType property? If so, how is it set programtically? DataType = System.DateTime gives a build error.

Thanks
Jonathan

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 12 Jun 2008, 06:59 AM

Hi Jonathan,

Can you check the DataType of the Datafield "ScheduledArrivalTime" in  your DataBase. Try setting the DataType  to datetime and see whether sorting is working properly.

Princy.

0
Jonathan
Top achievements
Rank 1
answered on 12 Jun 2008, 03:24 PM
That was it. The field was defined as DateTime in the database but was being converted to a string in the web service before sending back to the UI. The web service now sends back a data type of DateTime and the sort works now.

Thanks Princy!
Tags
Grid
Asked by
Jonathan
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Jonathan
Top achievements
Rank 1
Share this question
or