Thursday, June 16, 2011

CalendarExtender - Ajax Control Toolkit for ASP.NET

CalendarExtender

If you have ever used the CalendarExtender, you might have received a "Specified cast is not valid" error if populating it with null dates from the database using the SelectedDate property.

-Handling dbnull.

The following SelectedDate property correctly handles dbnulls in the data:

<cc1:CalendarExtender ID="calActivityDate" runat="server"


TargetControlID="txtActivityDate"


SelectedDate='<%# Convert.IsDBNull(Eval("activityDate")) ? null : Eval("activityDate") %>'


PopupButtonID="imgActivityDate" />