Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I have never created bindable controls before, but I would like to make suggestion. How about setting your <code>DateTimeOffset</code> property to be of type <code>Object</code>. That way, the property will accept any data types including DBNull. </p> <p>And once inside the <code>Set</code> code, check if the value passed is DBNull.Value. If so, create a new empty DataTimeOffset? object and save it in the ViewState.</p> <p>If non DBNull values, throw error if it cannot be be converted to datetime.</p> <p>I didn't try this though so I don't know if this will work or not.</p> <p><strong>################ UPDATED ANSWER ################</strong></p> <p>My suggestion is, you create 2 properties as follows:</p> <pre><code>Public Property DateTimeOffset() As DateTimeOffset? Get Return DirectCast(ViewState("DTO"), DateTimeOffset?) End Get Set(ByVal Value As DateTimeOffset?) ViewState("DTO") = Value End Set End Property &lt;Bindable(True, BindingDirection.TwoWay)&gt; Public Property DbDateTimeOffset As Object Get Return Me.DateTimeOffset End Get Set(value As Object) If IsDBNull(value) OrElse value Is Nothing Then Me.DateTimeOffset = New DateTimeOffset? Else Me.DateTimeOffset = DirectCast(value, DateTimeOffset?) End If End Set End Property </code></pre> <p>So in your markup, the binding will be to the <code>DbDateTimeOffset</code> property:</p> <pre><code>DbDateTimeOffset='&lt;%# Bind("myDateTimeOffsetField") %&gt;' </code></pre> <p>While in code behind, you can use the other property to read the property without having to cast.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload