Hi to all,
I think this question may already have been posted but I couldn't find
any post on this so I'm asking again.
I've a FormView bound to a SQLDataSource.
I've edited the EditItemTemplate placing some checkboxes bound to some
fields. I'm using Bind(FieldName) declarative syntax cause I need to
update these fields. In the source these fields my be empty (null).
When I switch to edit view I get the following error:
Conversion from type 'DBNull' to type 'Boolean' is not valid.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.
Exception Details: System.InvalidCastException: Conversion from type
'DBNull' to type 'Boolean' is not valid.
Source Error:
Line 86: <asp:CheckBox ID="CheckBox1" runat="server"
Checked='<%# Bind("F01MINORI") %>' CssClass="radiolist"
Line 87: Style="z-index: 124; left: 124px;
position: absolute; top: 293px" Text="minore" />
Line 88: <asp:CheckBox ID="CheckBox2" runat="server"
Checked='<%# Bind("F01MINORIH") %>' CssClass="radiolist"
Source File: x:\xxx\xxxxxxx.aspx Line: 86
Now, the source of this error is pretty clear to me. The fields is
empty and conversion from DBNull object to boolean value can not
happen. My question is, being forced to use Bind(), how can I handle
empty fields (not only for checkboxes but for bound controls in
general)?
Is there another way to bind two-way controls?
Thanks in advance.