I have an ASP.Net 3.5 page that contains a FormView control, bound to a Business Object using an ObjectDataSource.
One of the properties of the business object is a DateTime type, and I want to do 2 way databinding for this object, including the DateTime property.
I use a custom format for displaying the DateTime property, as shown here:
<asp:TextBox ID="TextBoxDate" runat="server" Text='<%# Bind("Date", "{0:d MMM yyyy HHmm}") %>' />
It displays just fine. The problem is when I attempt to perform an Update. I get the following exception:
String was not recognized as a valid DateTime.
My ObjectDataSource contains an explicitly set UpdateParameter for this Property, but it doesn't appear to make any difference.
<UpdateParameters>
<asp:Parameter Name="Date" Type="DateTime" />
</UpdateParameters>
What am I doing wrong?
UPDATE:
It turns out that if I change my format string in my Bind expression to
{0:d MMM yyyy HH:mm}
(Notice the colon between the HH and the mm)
... then the two way data-binding works as expected. Sadly, this isn't exactly what I wanted. I was hoping to use the 24 hour clock without a colon, hence my original format string. This is still not working, and I would love to know why? And even better, I'd love to know how I can work-around this shortcoming in the framework, but still do declarative databinding.
Thanks.