>>Hi everybody,
>>
>>I'm getting mycontrols "has a SelectedValue which is invalid because it does not exist in the list of items" error. I know how to fix this for the particular value I'm trying to pass, but is there a generic way to check if the value you want to assign a selectedvalue is in the list of Items?
>>
>>Thanks a lot in advance.
>
>What control is it (base class)? Could you post some code?
DropDownList (Web Forms).
In my UserControl I have (I added a check for empty value)
[Bindable(true, BindingDirection.TwoWay), Category("User-Defined"), DefaultValue(""), Description("Payment Method") ]
public string PaymentMethod
{
get
{
return this.ddlPaymentMethod.SelectedValue;
}
set
{
if (value !="") // Here we have error if value is not in the list
this.ddlPaymentMethod.SelectedValue = value;
}
}
If it's not broken, fix it until it is.
My Blog