|
|
 |
| ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 2.0 Basics section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|
 |

October 24th, 2009, 12:16 PM
|
|
Registered User
|
|
Join Date: Aug 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Conversion from type 'DBNull' to type 'Boolean' is not valid.
Hi,
I have a formview that contains OT and PT checkboxes that set to allow nulls in the database. I'm getting the error I've posted below. I've googled the error and "think" I will require codebehind to get past this but for the life of me don't know what to write nor what event it should be put under. I'm used to programming in Access so this is still pretty new to me and frustrating!!! Any help would be appreciated.
Thanks,
Leesha
Conversion from type 'DBNull' to type 'Boolean' is not valid.
Source Error:
Line 402: <asp:Label ID="GradeLabel" runat="server" Text='<%# Bind("Grade") %>'></asp:Label><br />
Line 403: OT:
Line 404: <asp:CheckBox ID="OTCheckBox" runat="server" Checked='<%# Bind("OT") %>' Enabled="false" /><br />
Line 405: PT:
Line 406: <asp:CheckBox ID="PTCheckBox" runat="server" Checked='<%# Bind("PT") %>' Enabled="false" /><br />
|

October 24th, 2009, 07:53 PM
|
 |
Wrox Author
|
|
Join Date: Jan 2008
Location: Decatur, IL, USA.
Posts: 807
Thanks: 12
Thanked 140 Times in 140 Posts
|
|
Before you can handle this, you need to decide exactly how you intend to display a null OT or a null PT.
Right now, you are attempting to display a three-valued property with a two-valued control. In other words, there are THREE possible values for OT and PT: true, false, and NULL. However, there are only two states for a checkbox: checked and unchecked.
You would normally show a true value with a checked checkbox; and a false value with an unchecked checkbox. But, how do you intend to display a NULL value for OT or PT?
You could write code to show a NULL value as an unchecked checkbox, for example. But that way, there is now way to distinguish a NULL from a false when the values are displayed. Does that make sense?
|

October 24th, 2009, 11:15 PM
|
|
Registered User
|
|
Join Date: Aug 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I'm sorry for posting twice. I was having trouble with my internet and the page seemed to be stuck.
Under Misc. in the properties I have checked = false. Is this what you mean?
Thanks,
Leesha
|

October 27th, 2009, 04:07 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,328
Thanks: 0
Thanked 1 Time in 1 Post
|
|
What he is saying is that a checkbox can only have 2 possible values, TRUE or FALSE. The problem you are having is that you are getting NULL values and a checkbox does not know how to display that. What you have to decide is that when you get a NULL back from your datasource, how do you want to display the checkbox, as checked or not checked?
I think the main problem here is that a boolean/bit data type should not allow NULLs.
|

October 28th, 2009, 04:38 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Location: Tehran, Iran
Posts: 922
Thanks: 0
Thanked 1 Time in 1 Post
|
|
u may set a default for ur field in Dataset or use IsNull() in DB
__________________
Always[:)],
Hovik Melkomian.
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |