473,473 Members | 2,074 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

formview and checkboxes

hey all,
i'm trying to bind my dataset to a formview but i get a message that says:
Conversion from type 'DBNull' to type 'Boolean' is not valid.

in order to fix this do i have to specify false for the bit field in the
database or is theere a config in formview i can modify to accept it?

thanks,
rodchar
Oct 2 '06 #1
2 2571
Hi,

I'd use a helper function to make sure a DBNull doesn't upset the formview.
Some sample code below.

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
Function FixDBNull(ByVal inVal As Object) As String
If inVal Is DBNull.Value Then
Return "false or other string"
Else
Return inVal
End If
End Function

Function CreateDataSource() As Data.DataTable
Dim dt As New Data.DataTable
Dim dr As Data.DataRow
dt.Columns.Add(New Data.DataColumn _
("IntegerValue", GetType(Int32)))
dt.Columns.Add(New Data.DataColumn _
("StringValue", GetType(String)))
dt.Columns.Add(New Data.DataColumn _
("CurrencyValue", GetType(Double)))
dt.Columns.Add(New Data.DataColumn _
("Boolean", GetType(Boolean)))
dr = dt.NewRow()
dr(0) = 0
dr(1) = "Item 0"
dr(2) = 1.23
dr(3) = DBNull.Value
dt.Rows.Add(dr)
Return dt
End Function

Protected Sub Page_Load _
(ByVal sender As Object, ByVal e As System.EventArgs)
If Not IsPostBack Then
FormView1.DataSource = CreateDataSource()
FormView1.DataBind()
End If
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Formview and Nulls</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:formview id="FormView1" runat="server">
<itemtemplate>
<asp:label id="Label2" runat="server"
text='<%#eval("StringValue") %>'></asp:label><br />
<asp:label id="Label3" runat="server"
text='<%#eval("CurrencyValue","{0:C}") %>'></asp:label><br />
<asp:label id="Label1" runat="server"
text='<%#FixDBNull(eval("Boolean")) %>'></asp:label>
</itemtemplate>
</asp:formview>

</div>
</form>
</body>
</html>

"rodchar" <ro*****@discussions.microsoft.comwrote in message
news:AF**********************************@microsof t.com...
hey all,
i'm trying to bind my dataset to a formview but i get a message that says:
Conversion from type 'DBNull' to type 'Boolean' is not valid.

in order to fix this do i have to specify false for the bit field in the
database or is theere a config in formview i can modify to accept it?

thanks,
rodchar

Oct 2 '06 #2
Thank you.

"Ken Cox [Microsoft MVP]" wrote:
Hi,

I'd use a helper function to make sure a DBNull doesn't upset the formview.
Some sample code below.

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
Function FixDBNull(ByVal inVal As Object) As String
If inVal Is DBNull.Value Then
Return "false or other string"
Else
Return inVal
End If
End Function

Function CreateDataSource() As Data.DataTable
Dim dt As New Data.DataTable
Dim dr As Data.DataRow
dt.Columns.Add(New Data.DataColumn _
("IntegerValue", GetType(Int32)))
dt.Columns.Add(New Data.DataColumn _
("StringValue", GetType(String)))
dt.Columns.Add(New Data.DataColumn _
("CurrencyValue", GetType(Double)))
dt.Columns.Add(New Data.DataColumn _
("Boolean", GetType(Boolean)))
dr = dt.NewRow()
dr(0) = 0
dr(1) = "Item 0"
dr(2) = 1.23
dr(3) = DBNull.Value
dt.Rows.Add(dr)
Return dt
End Function

Protected Sub Page_Load _
(ByVal sender As Object, ByVal e As System.EventArgs)
If Not IsPostBack Then
FormView1.DataSource = CreateDataSource()
FormView1.DataBind()
End If
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Formview and Nulls</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:formview id="FormView1" runat="server">
<itemtemplate>
<asp:label id="Label2" runat="server"
text='<%#eval("StringValue") %>'></asp:label><br />
<asp:label id="Label3" runat="server"
text='<%#eval("CurrencyValue","{0:C}") %>'></asp:label><br />
<asp:label id="Label1" runat="server"
text='<%#FixDBNull(eval("Boolean")) %>'></asp:label>
</itemtemplate>
</asp:formview>

</div>
</form>
</body>
</html>

"rodchar" <ro*****@discussions.microsoft.comwrote in message
news:AF**********************************@microsof t.com...
hey all,
i'm trying to bind my dataset to a formview but i get a message that says:
Conversion from type 'DBNull' to type 'Boolean' is not valid.

in order to fix this do i have to specify false for the bit field in the
database or is theere a config in formview i can modify to accept it?

thanks,
rodchar


Oct 2 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: mark d. | last post by:
I'm using a formview control to display/edit/insert data that is populated from an sqldatasource. One of the values is a pipe delimited string that represents multiple items. Within the...
2
by: Phil Sandler | last post by:
I am trying to do something which seems (to me) to be very simple, and yet I can't seem to figure it out. I have a gridview and a formview. When a user clicks "select" in the gridview, the...
1
by: Pao | last post by:
I have a formview bounded to an objectdatasource. All ok but I have some trouble with a checkbox: when I am in update mode and I update the record, this field is never updated (no errors thrown)....
1
by: Trev | last post by:
Hi, I'm hoping that someone in this group can shed some light on an issue I'm having with a Formview. I have a Web User Control (.ascx) with a Formview. The Formview contains 2 Multiviews,...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.