I created a simple CompositeControl and discovered the Nullable DateTimeOffset property. I bind the control to SQL Server DateTimeOffset fields using
DateTimeOffset='<%# Bind("myDateTimeOffsetField") %>'
This works fine when the DateTimeOffset field has a value. But when the field is NULL, I get the error "The specified movie is not valid."
How to stop this error and set my Nothing property when the field is NULL?
I thought this would be the default behavior!
Property Definition:
Public Property DateTimeOffset As DateTimeOffset?
Next comment:
I found that this works if I switch from using Bind to:
DateTimeOffset='<%# iif(IsDbNull(Eval("myDateTimeOffsetField")), Nothing, Eval("myDateTimeOffsetField")) %>'
But then I do not get the "myDateTimeOffsetField" passed as an argument in the FormView.ItemUpdating event (yes, this is in the FormView control), since ASP.NET assumes that I am not bound to the database.
Actual code (added on request)
This property in my composite control I'm trying to bind to:
Public Property DateTimeOffset As DateTimeOffset? Get Return CType(ViewState("DTO"), DateTimeOffset?) End Get Set(value As DateTimeOffset?) ViewState("DTO") = value End Set End Property
Here is the markup for snapping. The control is located in the EditItemTemplate FormView, which is bound to an SQL DataSource that returns a field named [dtoMldRejOn] with an optional DateTimeOffset value.
<APS:DateTimeOffsetControl runat="server" id="dtocMldRejOn" TextBoxCssClass="inputdatetime" ValidationGroup="vw1" FieldName="<%$ Resources: Resource, rxgFrom %>" DateTimeOffset='<%# Bind("dtoMldRejOn") %>' WindowsTimeZoneID="<%# me.WindowsTimeZoneID %>" IsRequired="false" />
As you can see, my Composite control is designed to handle DateTimeOffset values. All of this works fine, if the DateTimeOffset [dtoMldRejOn] field from the database is NULL, then I get an exception.