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

Trying to bind date to a datepicker

1 Answer 79 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jocelyn
Top achievements
Rank 1
Jocelyn asked on 07 Sep 2012, 02:37 PM
Hi,

like the title says, I am trying to bind a date to a date picker.

Here is my code:

<telerik:RadDatePicker ID="rdpDateDebut" runat="server" SelectionOnFocus="SelectAll"
    Width="100px" DbSelectedDate='<%# Bind("Date") %>'>
</telerik:RadDatePicker>

This is inside a ascx used in an edit form UserControl.

I always got the same error:

Uncaught Sys.WebForms.PageRequestManagerServerErrorException: Sys.WebForms.PageRequestManagerServerErrorException: Impossible de créer un objet de type 'System.Nullable`1[[System.DateTime, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' à partir de sa représentation sous forme de chaîne, '', pour la propriété 'SelectedDate'.  

My code looks very simple and I don't understand this error.

Sorry, the error is in french.

Thanks.

1 Answer, 1 is accepted

Sort by
0
Vasil
Telerik team
answered on 12 Sep 2012, 10:18 AM
Hi Jocelyn,

The error means that "Date" field that you are binding to does not contain valid date, and can't be cast to DateTime object.

This usually happens when you store the date in your database server as string in culture different from the one that you use in your ASP server. You should store the date time as datetime type and not a string in your database, or to make sure that the string can be parsed successfully using the DateTime.Parse method in the InvariantCulture.

Regards,
Vasil
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Jocelyn
Top achievements
Rank 1
Answers by
Vasil
Telerik team
Share this question
or