473,499 Members | 1,681 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("DirectorID") %>' . 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:DropDownList ID="drpTeamDirector" AppendDataBoundItems="True"
SelectedValue='<%# nulltest(eval("DirectorID")) %>' runat="server"
DataSourceID="odsEmployees" DataTextField="Name"
DataValueField="EmployeeID">
<asp:ListItem Selected="True" Value="0">Please Select</asp:ListItem>
</asp:DropDownList>

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 1123
OK I've figured it out. A blank value maps to null.
"Chris" <no****@nospam.comwrote in message
news:%2****************@TK2MSFTNGP05.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("DirectorID") %>' . 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:DropDownList ID="drpTeamDirector" AppendDataBoundItems="True"
SelectedValue='<%# nulltest(eval("DirectorID")) %>' runat="server"
DataSourceID="odsEmployees" DataTextField="Name"
DataValueField="EmployeeID">
<asp:ListItem Selected="True" Value="0">Please Select</asp:ListItem>
</asp:DropDownList>

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
4065
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...
6
1572
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...
4
1753
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. ...
1
3340
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....
2
2647
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...
6
2840
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...
0
1989
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...
6
3919
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...
6
1850
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...
0
2478
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. ...
0
7128
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
7006
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...
1
6892
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...
0
7385
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...
1
4917
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...
0
4597
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...
0
3088
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
661
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
294
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.