DropDownList Has A Selected Value Which Is Invalid Because It Does Not Exist

Aug 18, 2011

I have had some issues with processing null values stored in a SQL Server database table that needed to be represented in a DropDownList. Inevitably if the value wasn't there [meaning that any value in the database must match one of the values in the DropDownList otherwise] you would get the following error:

'DropDownList' has a SelectedValue which is invalid because it does not exist in the list of items

My earlier solution to this problem was to not allow null values resulting in making sure that all fields had default values, and that all DropDownList boxes were equipped with and entry called "Select this" or some such nonsense. Of course this value would also be the default value in said field, which even I would have to admit, looked quite stupid. Enter my co-worker and classic ASP guy who insists that null values are OK in a database (I tend to come from the "No Null values allowed camp.") One look at my code, which looked like this:

Code:
<asp:DropDownList ID="JointType" runat="server"
SelectedValue='<%# Bind("JointType") %>'>
<asp:ListItem>Select Joint Type</asp:ListItem>
<asp:ListItem>Mechanical</asp:ListItem>
<asp:ListItem>Push</asp:ListItem>
</asp:DropDownList>

Prompted him to say "Why aren't you doing that this way?", where "this way" looks like the following:

Code:
<asp:DropDownList ID="JointType" runat="server"
SelectedValue='<%# Bind("JointType") %>'>
<asp:ListItem Value="">Select...</asp:ListItem>
<asp:ListItem>Mechanical</asp:ListItem>
<asp:ListItem>Push</asp:ListItem>
</asp:DropDownList>

This causes a "Select..." to be displayed in the DropDownList when a null value is found in the database.

View 17 Replies


Similar Messages:

DDL Selected Value Which Is Invalid Because It Does Not Exist In List Of Items

Mar 15, 2016

I am attempting to load a page to edit previously saved info from a SQL2008R2 database. When a drop down index changes, it is supposed to load the existing data from a table. Most fields work OK, but drop down lists throw the error. The list is bound to a different database and table from the existing data that is to be edited (if that makes sense). So, when the data is called for editing, that comes from tableB. The drop down list is bound to a different data source, tableA. When the initial data entry was done, the item exists in the table, so I fail to see why this error is thrown. There are many dealing with this symptom, and I have tried many proposed solutions with no good result. Here's the code that retrieves the data and throws the error...

ASPX code:

Code:
Product Brand Name: <asp:DropDownList ID="product" runat="server" AppendDataBoundItems="True" DataSourceID="SqlDataSource19" DataTextField="Brandname" DataValueField="Brandname" AutoPostBack="true"><asp:ListItem> </asp:ListItem></asp:DropDownList>  

The SQLDataSource19 is from tableA.
VB:

Protected Sub DropDownList6_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DropDownList6.SelectedIndexChanged
Dim conn As New SqlConnection("Data Source=server;Initial Catalog=database;User ID=user;Password=password")
Dim cmd As New SqlCommand
Dim reader As SqlDataReader

[Code] ....

The data is bring called from tableB. The error is getting thrown on the product.selectedvalue line..I think I understand the problem, but I am not sure how to resolve it.

View 3 Replies

Web Forms :: DropDownList Has A SelectedValue Which Is Invalid Because It Does Not Exist In The List Of Items?

Mar 5, 2010

I have a page with some bound DropDownLists (DDLs) for a Call Logging system. The Calls are categorised on three levels for example:

Call: 3069, Category 1: Incident, Category 2: Microsoft Application, Category 3: Word would be used to organise calls for problems with Microsoft Word. On testing the system, I noticed that there was no handling for opening a call if the category had been deleted - say for reorganisation/systems no longer supported whatever. So I set about trying to make the program behave in the following manner:

Check category ID exists in DDL before bindingIt doesn't: set the displayed text of the DDL to Category Name + "(Deleted)"Disable the control to prevent user changingMove on to next control Seemed simple enough, however no matter which way I try and do it I always get the messase ddl_Cat1 has a SelectedValue which is invalid because it does not exist in the list of items. What's really puzzling me is that the exception doesn't seem to be being thrown in the code behind. I've gone through line by line from Page_Init and it never throws and exception. Just when the page loads this appears.

Does anyone know of a reason as to why this wouldn't work? (I've already tried setting the selected value to an existing item, adding a new list item with the value and setting DataSource property to Nothing - in all different combinations.)

View 12 Replies

Data Controls :: DropDownList Has A SelectedValue Which Is Invalid Because It Does Not Exist In The List

Jun 9, 2013

Before this, everything is fine when running the project After I've put "SelectedValue" below to the field,

<asp:TemplateField HeaderText="Interest">
<ItemTemplate>
<asp:DropDownList ID="ddl" OnSelectedIndexChanged="ddl_IndexChanged" SelectedValue='<%# bind("int_id") %>' AutoPostBack="true" runat="server">
</asp:DropDownList>
</ItemTemplate>

[CODE]

View 1 Replies

Data Controls :: DropDownList Has SelectedValue Which Is Invalid Because It Does Not Exist In List Of Items

May 7, 2015

I got this error when select a row from a grid view to update

'ddl_ctegOf_Product_update' has a SelectedValue which is invalid because it does not exist in the list of items.Parameter name: value
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.ArgumentOutOfRangeException: 'ddl_ctegOf_Product_update' has a SelectedValue which is invalid because it does not exist in the list of items.Parameter name: value

Source Error: 
Line 265: txt_prodID_update.Text = gridTo_updateFrom.SelectedRow.Cells[1].Text;
Line 266: txt_prod_name_update.Text = gridTo_updateFrom.SelectedRow.Cells[2].Text;
Line 267: ddl_ctegOf_Product_update.SelectedValue = gridTo_updateFrom.SelectedRow.Cells[3].Text;
Line 268: txt_cateIn_hardCopy_update.Text = gridTo_updateFrom.SelectedRow.Cells[4].Text.Replace(" ", "");
Line 269: txt_prodID_update.ReadOnly = true;

The code of update:

 private void PopulateDropDownList() {
string constr = ConfigurationManager.ConnectionStrings[1].ConnectionString;
using (SqlConnection con = new SqlConnection(constr)) {
using (SqlCommand cmd = new SqlCommand("SELECT CategoryProd_ID,Cate_Pro_Name FROM CategoryOfProduct", con)) {
using (SqlDataAdapter da = new SqlDataAdapter(cmd))

[Code] .....

View 1 Replies

Data Controls :: Dropdownlist Error - SelectedValue Invalid Because It Does Not Exist In List Of Items

Feb 24, 2013

I want to update the data using vb.net , my webpage has many dropdownlistlist ,

I got an error when update the dropdown field ,

"Dropdownlist error: SelectedValue which is invalid because it does not exist in the list of items."

View 1 Replies

AJAX :: 'dropdownlistArea' Has A SelectedValue Which Is Invalid Because It Does Not Exist In The List?

May 18, 2010

I am gettng the above error when I am using the Cascading Dropdown list in a DNN application. Everything works 100% until I try to post the form to the db then the error is thrown.I have attached the relevent code

[Code]....

View 1 Replies

'cmbslot' Has A Selectedvalue Which Is Invalid Because It Does Not Exist In The List Of Items Parameter Name Value

Mar 7, 2010

i try to fetch the data from the database and display text in the dropdownlist

i got the error message

'cmbslot' has a selectedvalue which is invalid because it does not exist in the list of items parameter name value cmbslot.Text = obj.getdata(dr["slotcode"].ToString()); //here is my code to retrive the data from the database

View 6 Replies

Forms Data Controls :: 'DropDownList1' Has A SelectedValue Which Is Invalid Because It Does Not Exist In The List Of It?

Jan 24, 2011

We use gridview for showing a data from table.It show fine in certain case like in table field dispostion is data and test but in table we put the string Ineligible Member/Member No Longer Enrolled - Spoke to Target and Wrong Number After Skip Tracing then it gives error. 'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of items.

The following is snippest my code ,tell me where i am wrong.

[Code]....

View 5 Replies

Forms Data Controls :: Getting - "'DropDownList1' Has A SelectedValue Which Is Invalid Because It Does Not Exist?

Dec 29, 2010

I've got a gridview which displays records from a table in SQL Server. Next I've got a details view which displays the details from the selected record. This works fine.

When the user selects a record, which then gets displayed in the details view, I'd like to make it possible for the user to edit the record. I've done searchs for this online, and found lots of responses, but none quite displaying an answer to the question I've got. I'm sure it is a simple thing I've done wrong, but at this point I don't know what it is I've done wrong. I've getting this error,"'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of items.Parameter name: value".

I've got a SqlDataSource to display the data in the details view. And then I specified another SqlDataSource to use for the dropdownlist control in the details view. I converted the field, in the details view, to a template field and have been replacing it. Here's the SqlDataSource controls definitions:

[Code]....

and here's the info for the details view:

[Code]....

View 2 Replies

Forms Data Controls :: 'DropDownList6' Has A SelectedValue Which Is Invalid Because It Does Not Exist In The List Of It?

Oct 5, 2010

In my asp.net page I have a formview. In the formview's InsertItemTemplate I declare a dropdown list as below:

<td>
<asp:DropDownList ID="DropDownList6" runat="server" text='<%# Bind("District") %>'
DataSourceID="SqlDataSource6" DataTextField="District"
DataValueField="District">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource6" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [District] FROM [tblDistricts]"></asp:SqlDataSource>
</td>
and this works perfectly fine.
In the EditItemtemplate I declare a similar dropdownlist as below to edit district values:
<td>
<asp:DropDownList ID="DropDownList6" runat="server" selectedvalue='<%# Bind("District") %>'
DataSourceID="SqlDataSource6" DataTextField="District"
DataValueField="District">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource6" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [District] FROM [tblDistricts]"></asp:SqlDataSource>
</td>

But whenever I try to edit the data I get the error:

'DropDownList6' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value And the values I am trying to edit were entered into the table by the dropdownlist declared in the insertitemtemplate dropdownlist6 listed above. And no values were deleted from the table.

View 4 Replies

Data Controls :: DStation Has SelectedValue Which Is Invalid Because It Does Not Exist In List Of Items

Dec 17, 2013

How to solver this error? I am getting error for "DropDown"

Error: 'DStation' has a SelectedValue which is invalid because it does not exist in the list of items.Parameter name: value on line: DStation.DataBind();

My .cs code is below

string CommandText = ("select distinct StationName from stations where DeletionDate is null");
DStation.DataSource = DataManager.DatabaseManager.GetOrCreateConnection
(DataManager.DatabaseManager.ConnectionType.MySQL).GetData(CommandText);
DStation.DataTextField = "StationName";

[Code] .....

View 1 Replies

Getting Error "invalid Character" In Statement - Doesn't Exist In Pl / Sql Developer Oracle

Feb 9, 2011

I keep getting an error saying invalid character in asp.net for the following query below, however that error doesnt exist in my pl/sql developer oracle. see code below

[Code]....

I think it has to do with my commit, hence how I do include commit in an update directly in the asp.net side.

View 12 Replies

SQL Server :: How To Get The Last Date If Selected Does Not Exist

Oct 24, 2010

Date, Currency
10.10.2010 EUR
19.10.2010 USD
20.19.2010, EUR
21.10.2010, USD

If I have a date 9.10.2010, choose the nearst date 10.10.2010 EURIf I have a date 18.10.2010 (this date does not exist), choose the nearest date 19.10.2010If I have a date 25.10.2010, choose 21.10.2010 USD

View 3 Replies

Drop Down List Has A SelectedValue Which Is Invalid Because It Does Not Exist In The List Of Items

Mar 25, 2011

I am getting this error yet I know it to be untrue.This is the code:

ddlPartnerOrganisation.DataSource = agency.AgencyGetListOfEYDN();
string temp = ddlPartnerOrganisation.SelectedValue.ToString();
ddlPartnerOrganisation.DataValueField = "AgencyID"
;
ddlPartnerOrganisation.DataTextField = "AgencyName"
;
ddlPartnerOrganisation.DataBind();

View 4 Replies

C# - Binding DropDownList's SelectedIndex To 0 If Value Does Not Exist?

Mar 17, 2011

I have a DropDownList in a DetailsView, which binds a user's 'AllocatedUser' to a user in the Users table. Occasionally, we'll have some mishaps in the database where the user allocated isn't in the users table, which the DropDownList is filled with. In this case the site crashes and we get a 'SelectedValue does not exist in the list of items error'.What I want to do is catch any binding errors like that, and just set the DropDownList index to 0. I've tried something like this:

OnDataBinding='DoesExist("AllocatedUser",<%#Bind("AllocatedUser")%>)'

but it doesn't like the syntax of that.

View 1 Replies

Control Or Jquery Plugin Exist For Auto Complete DropDownList?

Nov 20, 2010

is there any Control or Jquery Plugin exist for asp.net Auto Complete DropDownList? link a sample here.I don't want use asp.net ajax control toolkit

View 1 Replies

Forms Data Controls :: Dropdownlist Selectedvalue Does Not Exist Error?

Mar 2, 2011

I have a drop down list inside a formview control's edititemtemplate and itemtemplate. The dropdown list is not bound to a data source. I am hard-coding the listitems for the drop down list. The formview is bound to a datasource. All I want to do is set the selectedvalue of the dropdown to what is in the record from the database. But I keep getting the error.

<asp:formview .....>
<edititemtemplate>
.... //some other controls like textboxes that are correctly bound and display the value from the datasource
<asp:dropdownlist ID=myddl runat=server cssclass=myclass selectedvalue='<%# eval("mychoice") %>'>
<asp:listitem value='0'>I dont know</asp:listitem>
<asp:listitem value='1'>Yes</asp:listitem>
<asp:listitem value='2'>No</asp:listitem>
</asp:dropdownlist
.....//rest of the edititem controls that display correctly.
</edititemtemplate>

Just for kicks, I added a textbox and set it's value to eval("mychoice") as well and it correctly prints 0,1 or 2. So, I know that there is no illegal value coming back from the datasource. It seems as something with the timing of events - when the listitems are getting bound to the ddl. The error I get is - "myddl has a selectedvalue which is invalid because it does not exist in the list of items".

View 4 Replies

C# - Disable Or Enable 2nd Dropdownlist In Aspx Based On Selected Choice Of The 1st Dropdownlist Box

Apr 15, 2010

I am having a problem with disabling DropDownList based on the chice of 1st DropDownList, there is no post back occuring, and it is a template based web app here is the current code:

<script type="text/javascript">
$(function() { var dropDownList1 = $('#<%= ddlUserType.ClientID %>');
var dropDownList2 = $('#<%= ddlMember.ClientID %>'); dropDownList1.change(function(e) {
if ( jQuery("#ddlUserType").val() != "ETOC") dropDownList2.removeAttr('disabled'); e.preventDefault();
else
dropDownList2.removeAttr('enabled'); e.preventDefault(); }
} );
</script>

what is happening now is page is blank and if I remove the above code everything shows, where I am going wrong. here is the plain and final javascript code which worked:

<script language="javascript">
function CheckDropDownState(lstbox)
{
if (lstbox.selectedIndex == 3) { document.forms[0].ddlMember.disabled = 1; }
else { document.forms[0].ddlMember.disabled = 0; }
}
</script>

and thew .aspx code: <asp:dropdownlist id="ddlUserType" runat="server" onclick="CheckDropDownState(this);"></asp:dropdownlist>

View 2 Replies

Web Forms :: Display All Items In Child DropDownList When ALL Is Selected In Parent DropDownList

Sep 6, 2012

protected void DDLzone1_SelectedIndexChanged(object sender, EventArgs e)
{
BindDistrict();
}

[Code]......

here when i click on ALL item from ddlzone1  it just "ALL" item in ddldistrict

i want when i select "ALL" item from ddlzone1 in ddldistrict14 show all data from database

View 1 Replies

Web Forms :: 'Dropdownlist' Has A SelectedValue Which Is Invalid / How To Fix It

Oct 1, 2010

I have a dropdown list that has a bind on it and I get this error. Why am I getting this error and what can I do to fix it. here is the code for the dropdown I currently have:

[Code]....

View 6 Replies

Disabling Dropdownlist Inside A Gridview Based On Value Selected On Another Dropdownlist?

Jan 11, 2011

what i m trying is i hav two dropdownlists inside the gridview... namely say ddonsiteoffsite and ddhours... now what i want is if the selectedtext of ddonsiteoffsite is "onsite" the ddhours should b disabled... i tried the code snippet but ... its not disabling the ddhours... can someone help me please..

<asp:TemplateColumn HeaderText=" OnSite/OffSite" >
<ItemTemplate>
<asp:DropDownList ID="ddOnsiteOffside" runat="server" onchange="ToggleOnOff(this)">
[code].....

View 2 Replies

Web Forms :: Select Item In DropDownList With Value From Database And Display Default Value If Does Not Exist

Aug 15, 2012

I have dropdown list in my page

BindDropDownList(DdlDistrict, "District1", "District", "ID");
DdlDistrict.Items.Insert(0, new ListItem("select district", "0"));

And I use this code for binding from database 

DdlDistrict.Items.FindByText(_dr["District"].ToString()).Selected = true;

Here if in database have value it show in ddldistrict 

Now I want if there wasn't any thing in database in dropdown list show  "select district"  that i define here 

DdlDistrict.Items.Insert(0, new ListItem("select district", "0")); 

View 1 Replies

AJAX :: Cascading Dropdownlist Has A SelectedValue Which Is Invalid?

May 20, 2010

I think this needs to be a sticky since this is not solved anywhere that I have been looking... I have been googling this for a while now and came across the answer by shear luck and a simple typo when I was writing the code...

Problem: I have 2 dropdown lists...

ddllist1 and ddlist2... Both are code-behind populated via a sql DB.

they are cascading lists via the ajax control.

I am trying to dynamically populate them with values from a DB for edit reasons.

When I try to get them populated I kept getting the error...

"dropdownlist has a SelectedValue which is invalid because it does not exist in the list of items"

Solution:

1) get the values from the DB or from where ever...

2) create a sql select to get the values from the ddl db

3) set the ID of the first DDL control to cddcontrol1.SelectedValue = id (this is a number)

4) set the value of the DDL to the string value ddlist2.SelectedValue = value (this is a string)

here is the code.

[Code]....

View 1 Replies

Data Controls :: How To Fill Second DropDownList When First DropDownList Value Is Selected

Dec 17, 2012

I am having a 2 dropdown list, in the first dropdown I have 3company names,for each company I am having separate tables,every table have a empcode, if the user select the  company name in the 1st dropdownlist, as per company selected the 2nd dropdownlist it will fill the  list of employee codes as per the selection..

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved