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,256 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

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…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

805 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