User-1420987958 posted
Problem: SelectedDate property won't work if you field in database is null. For example I tried: SelectedDate='<%# Eval("dateField") %>' . The page says "Specified cast is not valid.".
Ugh, that took me a while to get and couldn't find the solution anywhere online so I'm posting this if anyone has the same problem.
Write a simple function:
Public Shared Function selectDate(ByVal dateField As Object) As Object
If dateField Is DBNull.Value Then
Return Nothing
Else
Return CType(dateField, DateTime)
End If
End Function
Then you just call your SelectedDate like this: SelectedDate='<%# selectDate(Eval("dateField")) %>'
I added my function in a separate class called CommonFunctions in App_Code folder, because I will need it several times.
In this case I call it like this: SelectedDate='<%# CommonFunctions.selectDate(Eval("fst_date")) %>'
If anyone cares to explain how (and if it's better) I'd do the same with javascript, including "CommonFunctions" class.. that's cool [cool].