472,779 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,779 software developers and data experts.

Drop Down List Selected Value is Null Problem

I am using ASP.net 2.0 and trying to take advantage of the updated data
editing facilities provided through the SQLDataSource control and the
DetailsView control. The data is a record from a customer complaints table
and one of the fields on the DetailsView control is called ComplaintType.
The field is a template field and in insert mode and edit mode i have used a
DropDownList control bound to a set of keys and values in a ComplaintTypes
table and the SelectedValue is bound to the foreign key in the complaints
table that links to the complaint types table. The problem i am having is
that the way the complaints procedure works is that, the complaint comes in
by phone and the receptionist simply takes basic details like name address
and a text description of the complaint The complaint then gets passed to
the QA department who then assign it a complaint type among other things.
When the receptionist enters the initial data they simply do not get an
option to set the compaint type, it defaults to NULL and all is well.
However when someone from the QA dept. clicks a link to turn the DetailsView
control into edit mode, it generates a runtime error because the
SelectedValue property is bound to a field that is set to NULL and NULL isn't
an value in the dataset bound to the DataValueField property. This error is
iritating because all it means is that ASP.net is not able to determine which
item in the HMTL drop down list to set to "selected" but instead of doing the
sensible thing and just not setting anything and carrying on, it generates a
run time error. The only way round this i can think of is to set an item in
the ComplaintTypes table to "Not Set" and set this as the default value for
the foreign key in the complaints table. This works but is an inelegant
solution especialy as i want to give the QA department the ability to update
the complaint types table and if they delete the "Not Set" record it will
make the whole thing fall over, so i then have to make sure that they can't
do that. This problem also applies to a number of other fields that work in
exactly the same way so it is not just a one field problem. Is there a
better solution that i have missed out on. One that doesn't require there
to be a matching record in the foreign table for the each foreign key in the
local table, especially as all these foreign keys default to NULL.
Mar 22 '06 #1
2 8519
When you define the dropdownlist in your detailsView, try adding a static
listitem with value ="" and use the AppendDataBoundItems property of the
DropDownList
http://msdn2.microsoft.com/en-us/lib...ms(VS.80).aspx

For example,
<asp:DropDownList ID="ddlCountry" runat="server" DataSourceID="odsCountries"
SelectedValue='<%# Bind("Country")
%>'>
<asp:ListItem Value="">Not Set</asp:ListItem>
</asp:DropDownList>

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"clickon" wrote:
I am using ASP.net 2.0 and trying to take advantage of the updated data
editing facilities provided through the SQLDataSource control and the
DetailsView control. The data is a record from a customer complaints table
and one of the fields on the DetailsView control is called ComplaintType.
The field is a template field and in insert mode and edit mode i have used a
DropDownList control bound to a set of keys and values in a ComplaintTypes
table and the SelectedValue is bound to the foreign key in the complaints
table that links to the complaint types table. The problem i am having is
that the way the complaints procedure works is that, the complaint comes in
by phone and the receptionist simply takes basic details like name address
and a text description of the complaint The complaint then gets passed to
the QA department who then assign it a complaint type among other things.
When the receptionist enters the initial data they simply do not get an
option to set the compaint type, it defaults to NULL and all is well.
However when someone from the QA dept. clicks a link to turn the DetailsView
control into edit mode, it generates a runtime error because the
SelectedValue property is bound to a field that is set to NULL and NULL isn't
an value in the dataset bound to the DataValueField property. This error is
iritating because all it means is that ASP.net is not able to determine which
item in the HMTL drop down list to set to "selected" but instead of doing the
sensible thing and just not setting anything and carrying on, it generates a
run time error. The only way round this i can think of is to set an item in
the ComplaintTypes table to "Not Set" and set this as the default value for
the foreign key in the complaints table. This works but is an inelegant
solution especialy as i want to give the QA department the ability to update
the complaint types table and if they delete the "Not Set" record it will
make the whole thing fall over, so i then have to make sure that they can't
do that. This problem also applies to a number of other fields that work in
exactly the same way so it is not just a one field problem. Is there a
better solution that i have missed out on. One that doesn't require there
to be a matching record in the foreign table for the each foreign key in the
local table, especially as all these foreign keys default to NULL.

Mar 22 '06 #2
Hi
Thanks i didn't think of that, i didn't realise "" would map to null, but i
supose it must. I got round it by adding:

UNION
SELECT NULL AS ComplaintTypeID, NULL AS ComplaintTypeDescription

to the Select statment in the SQL datasource and it seems to work well.

"Phillip Williams" wrote:
When you define the dropdownlist in your detailsView, try adding a static
listitem with value ="" and use the AppendDataBoundItems property of the
DropDownList
http://msdn2.microsoft.com/en-us/lib...ms(VS.80).aspx

For example,
<asp:DropDownList ID="ddlCountry" runat="server" DataSourceID="odsCountries"
SelectedValue='<%# Bind("Country")
%>'>
<asp:ListItem Value="">Not Set</asp:ListItem>
</asp:DropDownList>

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"clickon" wrote:
I am using ASP.net 2.0 and trying to take advantage of the updated data
editing facilities provided through the SQLDataSource control and the
DetailsView control. The data is a record from a customer complaints table
and one of the fields on the DetailsView control is called ComplaintType.
The field is a template field and in insert mode and edit mode i have used a
DropDownList control bound to a set of keys and values in a ComplaintTypes
table and the SelectedValue is bound to the foreign key in the complaints
table that links to the complaint types table. The problem i am having is
that the way the complaints procedure works is that, the complaint comes in
by phone and the receptionist simply takes basic details like name address
and a text description of the complaint The complaint then gets passed to
the QA department who then assign it a complaint type among other things.
When the receptionist enters the initial data they simply do not get an
option to set the compaint type, it defaults to NULL and all is well.
However when someone from the QA dept. clicks a link to turn the DetailsView
control into edit mode, it generates a runtime error because the
SelectedValue property is bound to a field that is set to NULL and NULL isn't
an value in the dataset bound to the DataValueField property. This error is
iritating because all it means is that ASP.net is not able to determine which
item in the HMTL drop down list to set to "selected" but instead of doing the
sensible thing and just not setting anything and carrying on, it generates a
run time error. The only way round this i can think of is to set an item in
the ComplaintTypes table to "Not Set" and set this as the default value for
the foreign key in the complaints table. This works but is an inelegant
solution especialy as i want to give the QA department the ability to update
the complaint types table and if they delete the "Not Set" record it will
make the whole thing fall over, so i then have to make sure that they can't
do that. This problem also applies to a number of other fields that work in
exactly the same way so it is not just a one field problem. Is there a
better solution that i have missed out on. One that doesn't require there
to be a matching record in the foreign table for the each foreign key in the
local table, especially as all these foreign keys default to NULL.

Mar 22 '06 #3

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

Similar topics

4
by: Dan | last post by:
Can anyone offer suggestions on how to do this or if it is possible? I have a form that uses a drop down box and 2 text fields. What I am trying to do is have the value of each text box set by...
1
by: Dan | last post by:
This is one that has me stumped and I need an expert's input. Any ideas why the values from the second script-generated drop down list isn't recognized by the script to add time values to the...
2
by: Yoshitha | last post by:
hi I have 2 drop down lists in my application.1st list ontains itmes like java,jsp,swings,vb.net etc.2nd list contains percentage i.e it conatains the items like 50,60,70,80,90,100. i will...
5
by: Vigneshwar Pilli via DotNetMonster.com | last post by:
string connectionString1 = "server=(local); user=sa;password=sa; database=sonic"; System.Data.SqlClient.SqlConnection dbConnection1 = new System.Data.SqlClient.SqlConnection(connectionString1);...
4
by: nz mark in aus | last post by:
Hi there I am populating an empty <asp:dropdownlist on the client side using Javascript using the following code Heres my dropdown list <asp:dropdownlist id="ddlDealers"...
2
by: millertime90 | last post by:
Hi basically my problem is I have 2 drop down menus populated by my database the first populated by a field in the database and the 2nd populated with a relation to the value selected in the first...
1
by: abTech | last post by:
Have struggled a lot to get a filtered drop down in the normal html and that too editable ... i have used table like auto-completion etc ... This is the simplest solution for a filtered drop down ...
15
by: ajos | last post by:
Hello all, Im making a dependent drop down for my application for filtering purpose. I have populated the drop down from the database and retrieved in the html. <tr> <td valign="top"...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.