473,379 Members | 1,423 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Solution to: dropdownlist has a SelectedValue which is invalidbecause it does not exist in the list of items

I ran into this problem it ended up being a combination of this that
needed to be done.
I believe this will work for a bound list to.

The whole problem stems from the two-way binding which has caused me
several other headaches.

My example is derived from binding a DETAILSVIEW to a SQLDATASOURCE.
The field is then converted to a template field for which I modify the
EditTemplate for that
field to dropdownlist and then bind it to another sqldatasource for
the dropdown list values.

The error occurs because I am trying to edit the data and the
datafield is empty.
The NULL value causes the error because the value is not in the
dropdown list.

Solution

1) modify the AppendDataBoundItems property of the dropdownlist and
set it to true
and make sure it's bound to field you need to update.

2) add an and Item to the Collection and use something similar to "--
Select Username --"
depends on what the user will be selecting. Make sure the select
is set to true.

3) Modify the Select query for the sqldatasource that the detailsview
is bound to
to account for the null value have it match what was added to
collection in step 2

ISNULL(Username,'-- Select Username --') as Username

4) Step 3 takes care of the error but now you must account for the Two-
Way Binding
and insure that '-- Select Username --' is not the value saved
back to the database if nothing
else is slected from the list.

Modify the Update query back to the data for the same datasource
so a null value
is applied just in case '-- Select Username --' is still selected.

Username = NULLIF(@Username,'-- Select Username --')

Best I could come up with.
Mar 23 '08 #1
1 2264
OK, here's another view on this.... ( Untested )

Instead of having "--Select Username" as a Value AND as Text. Make the
value "" for the Value that way an empty field should select option 0 (
Select UserName ). This would solve the saving null values as well.

<ke**********@hotmail.comwrote in message
news:17**********************************@e23g2000 prf.googlegroups.com...
>I ran into this problem it ended up being a combination of this that
needed to be done.
I believe this will work for a bound list to.

The whole problem stems from the two-way binding which has caused me
several other headaches.

My example is derived from binding a DETAILSVIEW to a SQLDATASOURCE.
The field is then converted to a template field for which I modify the
EditTemplate for that
field to dropdownlist and then bind it to another sqldatasource for
the dropdown list values.

The error occurs because I am trying to edit the data and the
datafield is empty.
The NULL value causes the error because the value is not in the
dropdown list.

Solution

1) modify the AppendDataBoundItems property of the dropdownlist and
set it to true
and make sure it's bound to field you need to update.

2) add an and Item to the Collection and use something similar to "--
Select Username --"
depends on what the user will be selecting. Make sure the select
is set to true.

3) Modify the Select query for the sqldatasource that the detailsview
is bound to
to account for the null value have it match what was added to
collection in step 2

ISNULL(Username,'-- Select Username --') as Username

4) Step 3 takes care of the error but now you must account for the Two-
Way Binding
and insure that '-- Select Username --' is not the value saved
back to the database if nothing
else is slected from the list.

Modify the Update query back to the data for the same datasource
so a null value
is applied just in case '-- Select Username --' is still selected.

Username = NULLIF(@Username,'-- Select Username --')

Best I could come up with.

Mar 23 '08 #2

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

Similar topics

4
by: DotNetJunky | last post by:
I have built a control that runs an on-line help system. Depending on the category you selected via dropdownlist, it goes out and gets the child subcategories, and if there are any, adds a new...
3
by: mg | last post by:
I have a DataGrid (WebForm - C#) that has a template column that contains a dropdownlist named "DdlTest" In DataGrid1_UpdateCommand, the lin DropDownList ddlTest = (DropDownList)...
2
by: Benedict Teoh | last post by:
I created a dropdownlist containing day, month and year field and expose a property to assign a date. When I call from a aspx page and assign the value, the new date is not displayed until a submit...
1
by: clickon | last post by:
Forget about the controlParameter for the moment, for testing purposes i have created the following Markup: <asp:Table ID="tblSelectRoute" runat="server" CssClass="asp-table"> <asp:TableRow>...
11
by: Santosh | last post by:
Dear all , i am writting following code. if(Page.IsPostBack==false) { try { BindSectionDropDownlist();
1
by: mitchman10 | last post by:
My Time table has TimeID,Employee,PayPeriod,ChargeCodeID,Hours My Chargecode table has ChargecodeID,c_Text I need an Editable datagrid that will show the TimeID,Employee,PayPeriod,C_Text in a...
1
by: JJ | last post by:
Hi. I am having trouble getting a dropdownlist to work properly in a detailsview: The code is something like: <asp:DetailsView ID="dvwSubscriber" runat="server" AutoGenerateRows="False" ...
2
by: sree reddy | last post by:
..cs using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls;
1
by: Brett | last post by:
I have a DropDownList in an ASP.NET web form that is populated with items from a lookup table by binding that DropDownList to a SqlDataSource. However, the items in the lookup table can change over...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.