Não consigo entender o que esta mal. A DropDown esta em uma Formview de uma user control. A dropDown liga a uma tabela de base de dados que deve retornar 2 valores id e nome
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: 'EntregaRegiaoDropDownList' 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 o botao edit visible
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\ClientesDetalhes.ascx.cs Line: 32
Stack Trace:
[ArgumentOutOfRangeException: 'EntregaRegiaoDropDownList' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value]