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

GridView DateTimePicker Format Problems

2 Answers 204 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Pete
Top achievements
Rank 1
Pete asked on 28 Oct 2011, 08:37 AM
Hi There,

I am having difficulty understanding what is going wrong with my code.

I have a gridview wtih a datasource set to an entity framework object. In the gridview is a datetimepicker column that I want to show the date in the format "dd/MM/yyyy" the format of the information stored in my entity framework is in the format "dd/MM/yyyy" Upon loading the datagridview I populate the gridview with the information from my EF object. This works a deam and is as expected.

However the problems begin when I add a new row to the datagrid, no matter what I try when adding a new row the datetimepicker always sets the column to have a value including the time. I have set the format string correctly to "{0: dd/MM/yyyy}". If I stop the datasource binding to my EF object the date is added correctly to the new row. It seems that the problem only occurs If I use the datasource.

It would appear that this is a problem with the .fieldname I am using, if I remove this I have no problems.

Anyone offer any advice on what is going wrong here?

Many Thanks

2 Answers, 1 is accepted

Sort by
0
Pete
Top achievements
Rank 1
answered on 28 Oct 2011, 10:57 AM
I have since solved this by storing the date in my database as a datetime type rather than a string type. All works ok now. Sorry for wasting your time.

Thanks all the same.
0
Peter
Telerik team
answered on 31 Oct 2011, 04:12 PM
Hi Pete,

This happens, because the value from the grid editor is of type DateTime and this type always represents the time part, and this part will be saved in a string field without any restrictions.

Feel free to ask if you have any further questions.

Greetings,
Peter
the Telerik team

Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

Tags
GridView
Asked by
Pete
Top achievements
Rank 1
Answers by
Pete
Top achievements
Rank 1
Peter
Telerik team
Share this question
or