techques
asked on
SelectedValue which is invalid because it does not exist in the list of items.\r\nParameter name: value" string
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?
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();
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ten check whether you are getting data in currency filed
may be it is returning null data so it having problems
may be it is returning null data so it having problems
ASKER
it is very strange
i added break point to view it line by line
this.currency.DataTextFiel d = "currency";
this.currency.DataValueFie ld = "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.
i added break point to view it line by line
this.currency.DataTextFiel
this.currency.DataValueFie
They can get value in first time of loading, but I do not know why it loads the 2nd time and it became null.
ASKER
I found the error caused by the sequence of the function executed in page load.
ASKER
this.currency.DataSource = ds.Tables[0].DefaultView;
this.currency.DataTextFiel
this.currency.DataValueFie