I can not understand what's wrong. DropDown is in a Formview of a user control. The dropDown binds to a database table that should return 2 id and name values
FormView
<td><asp:DropDownList width="350px"
ID="EntregaRegiaoDropDownList" runat="server" SelectedValue='<%# Bind ("Regiao") %>' DataSourceID ="SqlDataSource1" DataTextField ="RegiaoNome" DataValueField ="RegiaoID" Enabled ="False"></asp:DropDownList></td>
Code behind userControl.ascx
public bool Editable
{
get
{
if (ViewState["editable"] != null)
{
return (bool)ViewState["editable"];
}
else
{
return true;
}
}
set
{
ViewState["editable"] = value;
}
}
protected override void OnPreRender(EventArgs e)
{
//Find o botao edit visible
Button EditButton=
FormView1 .FindControl ("EditButton") as Button;
if (EditButton !=null )
{
EditButton .Visible =Editable ;
}
}
DropDownList 'has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value
Exception Details: System.ArgumentOutOfRangeException: 'DeliveryRegiaoDropDownList' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value
Source Error:
Line 30: {
Line 31: // Find the visible edit button
Line 32: Button EditButton =
Line 33: FormView1 .FindControl ("EditButton") as Button;
Line 34: if (EditButton! = null)
Source File: c: \ Users \ PC \ Documents \ Visual Studio
2012 \ WebSites \ BaumSGVO \ UserControls \ ClientsDetails.ascx.cs Line: 32
Stack Trace:
[ArgumentOutOfRangeException: 'DeliveryRegiaoDropDownList' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value]