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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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.…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This video discusses moving either the default database or any database to a new volume.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

705 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

18 Experts available now in Live!

Get 1:1 Help Now