473,595 Members | 2,474 Online
Bytes | Software Development & Data Engineering Community
+ 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 2576
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.dt d">

<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 CreateDataSourc e() 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 _
("StringValu e", 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.EventArg s)
If Not IsPostBack Then
FormView1.DataS ource = CreateDataSourc e()
FormView1.DataB ind()
End If
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Formvi ew 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='<%#FixDBN ull(eval("Boole an")) %>'></asp:label>
</itemtemplate>
</asp:formview>

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

"rodchar" <ro*****@discus sions.microsoft .comwrote in message
news:AF******** *************** ***********@mic rosoft.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.dt d">

<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 CreateDataSourc e() 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 _
("StringValu e", 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.EventArg s)
If Not IsPostBack Then
FormView1.DataS ource = CreateDataSourc e()
FormView1.DataB ind()
End If
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Formvi ew 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='<%#FixDBN ull(eval("Boole an")) %>'></asp:label>
</itemtemplate>
</asp:formview>

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

"rodchar" <ro*****@discus sions.microsoft .comwrote in message
news:AF******** *************** ***********@mic rosoft.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
1780
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 edititemtemplate for this field I have a label and checkboxlist. Within the checkboxlist databound event I take the label and split up the string then set the appropriate checkboxes to selected. My question is how to update this field. I've looked...
2
2331
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 formview opens. The user can then click "insert" or "update" to either create a new row or edit the existing row. This all works fine as long as I only use textboxes and checkboxes in my insertItemTemplate and editItemTemplate. What I would like...
1
6560
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). The field bounded in the database (MySql) is a string field (ENUM('True','False') default 'False'. The checkbox is correctly bounded in the itemtemplate and in the edititemtemplate.
1
4329
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, one in the EditItemTemplate and one in the InsertItemTemplate. Each of those Multiviews contains several Views, and each view contains several controls such as textboxes, checkboxes etc. Those controls are bound to the Formview's datasource, which...
0
7955
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8261
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8019
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8251
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5839
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5418
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3873
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3911
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1490
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.