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

3 Use Cases for Connected Systems

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

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now