BINDing an ASP.NET 2.0 FormView - CheckBox or RadioButton to Oracle CHAR(1) Y/N RRS feed

  • Question

  • User1770285480 posted

    Title: BINDing an ASP.NET 2.0 FormView - CheckBox or RadioButton to Oracle CHAR(1) Y/N

    Since Oracle XE (and other versions too) does not has  BOOLEAN data type. CheckBoxes in ASP.NET are BOOLEAN controls.

    So I use  CHAR(1) column with Y or N values in the Oracle table,

    Question: how can I bind to a CheckBox or CheckBoxList or RadioButton or RadioButtonList control on an ASP.NET 2.0 web form?


    Monday, April 20, 2009 12:45 PM

All replies

  • User364663285 posted

    Here is an example
    <asp:CheckBox ID="cbxStatus" runat="server" Checked='<%# Eval("status").ToString() == "0" ? true:false %>'/>

    Tuesday, April 21, 2009 4:58 AM
  • User2001157048 posted

    Simple and awesome solution. I was doing all kinds of code-behind events and stuff in a freaking FormView. I found this to be the exact solution I needed. Thanks a mil

    Wednesday, September 9, 2009 4:07 PM
  • User1024785009 posted

    I've tried this now, however i get an error saying Expression Expected

    Compiler Error Message: BC30201: Expression expected.

    Source Error:

    Line 28:                 <br />
    Line 29:                 BMI:
    Line 30: <asp:CheckBox ID="BMITextBox" runat="server" Checked='<%# Eval("BMI").ToString() == "0" ? true:false %>' /> Line 31:                 <br />
    Line 32:                 HEIGHT:
    Tuesday, July 17, 2012 10:15 AM
  • User269602965 posted

    What works for me and Oracle is the following.

    Oracle SQL has no Boolean datatype.  Checkbox in ASP.NET expects a Boolean.

    Trial and error with all kinds of Boolean equivalents (T or F, Yes or No, etc.)

    I found this works:

    Store the Boolean value in Oracle VARCHAR2(5) column with case sensitive text values 'True' and 'False'

    then the Evaluation in the web page control will work as ASP.NET recognizes the words 'True' and 'False'.

    <asp:CheckBox ID="cbxFLAG_ACTIVE" runat="server" Checked='<%# IIf(Eval("FLAG_ACTIVE"), "True", "False") %>' />

    Bind in the web page control will store the value as 'True' or 'False' into the Oracle column you set up as VARCHAR2(5).

            <asp:Checkbox ID="cbxFLAG_ACTIVE" runat="server" Checked='<%# Bind("FLAG_ACTIVE") %>' Text="Check box if person is still Active" TextAlign="Left" /></td>

    Wednesday, July 18, 2012 6:22 PM
  • User1024785009 posted

    Hi there, Thanks for replying.

    I got this error when i did it. "Conversion from type 'DBNull' to type 'Boolean' is not valid."

    Thursday, July 19, 2012 4:33 AM
  • User269602965 posted

    Make the Oracle default value in the VARCHAR2(5) column 'False';

    ie. checkbox unchecked.

    Then there will be no nulls to insert or read.


    Thursday, July 19, 2012 9:43 AM