I need to bind a checkBox but with this line of code,
<asp:CheckBox ID="CheckBoxRed" runat="server" Checked='<%# Bind("red") %>'/>
because initially the value in the DB is null, I get an invalid cast. I therefore tried in this way:
<asp:CheckBox ID="CheckBoxRed" runat="server" Checked='<%# (DataBinder.Eval(Container.DataItem,"red") is DBNull ?false:Eval("red")) %>'/>
This avoids the initial invalid cast but if I check the checkbox the value is not saved to the db. Is there a way to avoid the initial invalid cast and get the checked/unchecked status saved into the db?
I already checked this answer but it does not bind the value.