473,566 Members | 3,255 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Bound control amd null values

I have some drop downs in a formview. I am binding them to a datasource with
the bind syntax e.g. SelectedValue=' <%# Bind("DirectorI D") %>' . This works
fine when there is a value to be bound to, but when the underlying data is
null I get an error saying the value is not in the list. I have used the
code below with the eval syntax, but I can't get it to work with bind. Can
anyone point me in the right direction or better still give an alternative
as this seems a bit fiddly. Ideally I would like to create a control which
adds a "Please select" item only if the underlying value is null. I haven't
got clue where to start with that.....

<asp:DropDownLi st ID="drpTeamDire ctor" AppendDataBound Items="True"
SelectedValue=' <%# nulltest(eval(" DirectorID")) %>' runat="server"
DataSourceID="o dsEmployees" DataTextField=" Name"
DataValueField= "EmployeeID ">
<asp:ListItem Selected="True" Value="0">Pleas e Select</asp:ListItem>
</asp:DropDownLis t>

Public Function nulltest(ByVal drpnull As Object) As Integer
If drpnull Is DBNull.Value Then
Return 0
Else
Return CInt(drpnull)
End If
End Function
May 13 '07 #1
1 1126
OK I've figured it out. A blank value maps to null.
"Chris" <no****@nospam. comwrote in message
news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
>I have some drop downs in a formview. I am binding them to a datasource
with the bind syntax e.g. SelectedValue=' <%# Bind("DirectorI D") %>' . This
works fine when there is a value to be bound to, but when the underlying
data is null I get an error saying the value is not in the list. I have
used the code below with the eval syntax, but I can't get it to work with
bind. Can anyone point me in the right direction or better still give an
alternative as this seems a bit fiddly. Ideally I would like to create a
control which adds a "Please select" item only if the underlying value is
null. I haven't got clue where to start with that.....

<asp:DropDownLi st ID="drpTeamDire ctor" AppendDataBound Items="True"
SelectedValue=' <%# nulltest(eval(" DirectorID")) %>' runat="server"
DataSourceID="o dsEmployees" DataTextField=" Name"
DataValueField= "EmployeeID ">
<asp:ListItem Selected="True" Value="0">Pleas e Select</asp:ListItem>
</asp:DropDownLis t>

Public Function nulltest(ByVal drpnull As Object) As Integer
If drpnull Is DBNull.Value Then
Return 0
Else
Return CInt(drpnull)
End If
End Function

May 13 '07 #2

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

Similar topics

19
4078
by: James Fortune | last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't understand why people who know how to write code to completely replace a front end do not write something that will automate the code that implements managing unbound controls on forms given the superior performance of unbound controls in a client/server environment. I can...
6
1578
by: BBM | last post by:
Hi, I'm having trouble getting control data binding to work. As I understand it, the simplest form of databinding requires three things: 1) A control (say a textbox) on a form or user control, 2) A field or object.member to which you want to bind, 3) A "Binding" object that connects the variable to a property of the control ("Text"...
4
1756
by: kaborka | last post by:
I have a WinForm with controls bound to a typed recordset that was generated by the Dataset Designer. There are several ComboBox controls with their DataSource bound to different lookup tables. Everything is working fine, except when I need to handle a null default value in the data record coming from the database. I want the combo whose...
1
3352
by: James | last post by:
I am used to VB6 but need to develop something in .Net. I need to create several bound combo-boxes which will use lookup tables to get their values. I created a form using the dataform wizard. As part of the setup, I specified a new dataset, which included the data & lookup tables. I also specified the relationships when required. I...
2
2651
by: Matt | last post by:
I have a number of TextBox controls bound to date fields in my application, and have come across a disconcerting issue: When you are entering data into the bound field, if you enter any string that cannot be converted by the system into the date/time format, the application will not allow you to leave the TextBox control, even to close the...
6
2857
by: dbuchanan | last post by:
VS2005 I've been reading all the help I can on the topic (MSDN, other) but I can't make sense of this. Desired behavior; The user is to choose from the displayed list of the databound combobox and the coresponding 'Id' from the lookup table is to be inserted into the field of the new record. I have two simple tables. "tblPerson" is the...
0
2000
by: Frnak McKenney | last post by:
Can I use a bound ComboBox for both browsing and editing? I'm working on a small, standalone database application using Visual C#.NET 2003 and an Access data file. In order to keep the number of different screens down to a minimum, I'm trying to use the same Windows Forms for both browsing and for updating. This works fine for TextBoxes,...
6
3923
by: blouie | last post by:
Is there a way that a bound ddl control can: 1. display the bound data, even if it does not match a selection in the DDL? 2. allow the user to enter something other than the look up values? I have a bound dropdown list that retrieves it's selections from a look-up table. The DDL is bound to a database table and unless the value in the...
6
1855
by: Jonathan Wood | last post by:
I have a databound dropdownlist control. Based on some other criteria, I need to specify the selected item in my pages Load event. The problem is that, in my load event, the control does not yet have any data. I've found I can call DataBind() on that control and then it works okay. However, this has me wondering where the control normally...
0
2485
by: Mike | last post by:
So here's the situation (.NET 2.0 btw): I have a form, and on this form is a textbox among many other databound controls. The textbox is bound to a field in a data table via the Text property. In this table there are multiple columns that cannot be NULL, which, are bound to other controls (but they're not really important at this time). ...
0
7673
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...
0
7584
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7893
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. ...
0
8109
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7953
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...
1
5485
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...
0
3643
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...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2085
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 we have to send another system

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.