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

DateColumn Doesn't sort

1 Answer 32 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Santhosh Kumar
Top achievements
Rank 1
Santhosh Kumar asked on 27 Oct 2008, 05:44 AM

I have a date column which is in MM/dd/yyyy format. This doesnt sort ascending or descending for all the grids in my application. I am sure what I have done is right. Still it doesnt sort right when I click on header. Please help. One way of doing it is after binding the data source by adding

 

radgvSixMonthPurchases.Columns[

"transactionDate"].FormatString = "{0:MM/dd/yyyy}";

 

 

and othe way is through cell formatting like:

 

 

private void radgvSixMonthPurchases_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e){
if (e.CellElement is GridDataCellElement)
{
Font font = new Font("Tahoma", 6.75F);
e.CellElement.Font = font;
if (((GridViewDataColumn)e.CellElement.ColumnInfo).FieldName == "transactionDate")
{
if (!e.CellElement.Text.StartsWith("0:"))
{
DateTime temp = DateTime.Parse(e.CellElement.Text);
e.CellElement.Text = temp.ToString(
"MM/dd/yyyy");
}
Font newfont = new Font("Tahoma", 7, FontStyle.Underline);
e.CellElement.Font = newfont;
e.CellElement.ForeColor =
Color.Blue;
}
}

 

1 Answer, 1 is accepted

Sort by
0
Nick
Telerik team
answered on 30 Oct 2008, 10:00 AM
Hello Santhosh Kumar,

Thank you for contacting us.

I cannot see the reason why sorting is not working correctly. The type of the date columns should be DateTime in order for sorting to work correctly on them which I guess is correct in your application. Can you send me a sample application demonstrating the issue? You can do so in a support ticket.

The sample code you sent to me is about formatting which is independent of sorting. Sorting dates does not depends on formatting, but on which date is earlier/later than other dates.

I am looking forward to help you on that.


 
All the best,
Nick
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
GridView
Asked by
Santhosh Kumar
Top achievements
Rank 1
Answers by
Nick
Telerik team
Share this question
or