ASP.NET Web Controls >> FormView checkbox two-way bind problem with null fields

by Deer Chief » Thu, 23 Feb 2006 01:16:33 GMT

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.


Similar Threads

1. Checkboxes in FormView bound to ObjectDataSource - Asp.Net

2. Disable checkbox when field value = null

3. Do not display a formview if one of its data bound fields is n - ASP.NET Web Controls

4. Simple question - Make Label1 = Bound Field in ItemTemplate of Formview

I'm a newbie.  Using VS2005 making a simple ASPX page for testing and 
learning.
I have a simple SQL connection.

I created a Formview and I am in EditItem Template.  I added a label 
(LABEL1) to the outside of the ItemTemplate and I have a button inside the 
template.  I want my Label1 to = my bound item (LastNameLable) inside the 
template when I click the button.  The code I thought would work is below, 
but I'm getting Label1 with a text "FALSE" when I click the button.

Thanks!
Phil



Protected Sub Button1_Click(ByVal sender As Object, ByVal e As 
System.EventArgs)

Dim nghia As String

nghia = FormView1.TemplateControl.ID.Contains("LastNameLabel")

Label1.Text = nghia


End Sub


5. Two-way Binding To CheckBox in GridView (ASP.Net 2.0) - ASP.NET Web Controls

6. Binding multiple checkboxes to a single data field

I have a form that uses databinding to update a database table.  One of the 
fields in the table corresponds to multiple checkbox controls in the form 
(Flags Attributes).  How can I perform the databinding in this case?

Thanks,

Jeronimo Bertran

7. About binding checkboxes and multiple row fields modification - VB.Net

8. Binding two fields in the DataNavigateUrlFormatString

Hi,
I would like to bind the hyperlink column but I don't see how to.

I tried somethink like this but instead of showing ID nummbers it shows 
"ID=ID"

Any tip is very much appreciated.

Genc


PS:
Code I tested with

aHLCol.DataTextField = "RR_ID"

aHLCol.DataNavigateUrlField = "FILEPATH"

aHLCol.DataNavigateUrlFormatString = "{0}?ID=" & 
resultTable.Column("ID").ToString ()

aHLCol.HeaderText = "http:/cnn.com/{0}"

dgSearchResults.Columns.Add(aHLCol)

dgSearchResults.DataSource = resultTable

dgSearchResults.DataBind()