GridView DateTimePicker Format Problems

3 posts, 0 answers
  1. Pete
    Pete avatar
    3 posts
    Member since:
    Oct 2011

    Posted 28 Oct 2011 Link to this post

    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. Pete
    Pete avatar
    3 posts
    Member since:
    Oct 2011

    Posted 28 Oct 2011 Link to this post

    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.
  3. Peter
    Peter avatar
    1148 posts

    Posted 31 Oct 2011 Link to this post

    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.

    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.

Back to Top