Solved

SelectedValue which is invalid because it does not exist in the list of items.\r\nParameter name: value"      string

Posted on 2009-05-08
5
1,258 Views
Last Modified: 2013-12-17
Hi

I use the following code to bind data in a drop down list in a aspx with c#, but it throws error:

Message      "'currency' has a SelectedValue which is invalid because it does not exist in the list of items.\r\nParameter name: value"      string

How should I fix it?
<asp:DropDownList Runat="server" ID="currency" CssClass="form" Width=60  />
 
private void Bind_Currency()
        {
            string strSql = "SELECT id,currency from currency order by id";
            DataSet ds = new DataSet();
            try
            {
                ds = SqlHelper.ExecuteDataset(DBConnection.ConnString, CommandType.Text, strSql);
            }
            catch (Exception)
            {
                Response.Redirect("../error.aspx", true);
            }
            this.currency.DataSource = ds.Tables[0].DefaultView;
            this.currency.DataTextField = "currency";
            this.currency.DataValueField = "currency";
            try
            {
                this.currency.DataBind(); //throw exception
            }
            catch (Exception e)
            {
                string r = e.ToString();
            }
        }

Open in new window

0
Comment
Question by:techques
  • 3
  • 2
5 Comments
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 50 total points
ID: 24334428
is it working

 this.currency.DataSource = ds.Tables[0].DefaultView;
            this.currency.DataTextField = "id";
            this.currency.DataValueField = "id";
0
 

Author Comment

by:techques
ID: 24334569
yes, it is working

this.currency.DataSource = ds.Tables[0].DefaultView;
            this.currency.DataTextField = "id";
            this.currency.DataValueField = "id";
0
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 24334934
ten check whether you are getting data in currency filed
may be it is returning null data so it having problems
0
 

Author Comment

by:techques
ID: 24335199
it is very strange

i added break point to view it line by line

this.currency.DataTextField = "currency";
this.currency.DataValueField = "currency";

They can get value in first time of loading, but I do not know why it loads the 2nd time and it became null.

0
 

Author Comment

by:techques
ID: 24360561
I found the error caused by the sequence of the function executed in page load.
0

Featured Post

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question