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,263 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

717 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