Don’t Use Boolean (Example Why)

I read this blog: Don’t use booleans and it made me think about the shortcomings of the standard ASP.Net checkbox control.
The ASP.Net standard checkbox control has only 2 states:
The shortfall is we can only search by “True” because if we allowed searching by “False” it would unintentionally filter out records.
For example, if you were searching by barcode “000001” the search criteria would be WHERE Barcode=’000001′ AND Closed=0 .  Closed would be set to 0 because the control’s value is False (only two states).
If the record assigned with the barcode 000001 is closed, it would not be part of the result even though we are searching by a barcode that identifies a specific record.
The checkbox was not explicitly set/changed it should beWHERE Barcode=’000001′ .  Therefore, when we use a checkbox control we can only search by “True” as we know that the user explicitly set the value of the checkbox.
One Solution: Need another state:
Use a drop-down control and keep the boolean data type in the database.  Added bonus, also allows searching by NULL (aka Not Set).
This drop-down “boolean” now has 4 states versus the 2 states the standard ASP.Net checkbox:
  • Blank (not selected and exclude from searching).
  • (Not Set) = NULL values only.
  • No = 0
  • Yes = 1

Leave a thought