'ddlCities' has a SelectedValue which is invalid because it does not exist in the list of items

this.ddlCities.DataSource = GetAll_List();
this.ddlCities.DataTextField = "Name";
this.ddlCities.DataValueField = "Id";
this.ddlCities.DataBind();

错误:

'ddlCities' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value

原因:

多次执行了绑定,因此会出现重复的ListItem。

解决方法:

(1)检查是否有多次绑定。

(2)添加 this.ddlCities.Items.Clear();

this.ddlCities.Items.Clear();

this.ddlCities.DataSource = GetAll_List();
this.ddlCities.DataTextField = "Name";
this.ddlCities.DataValueField = "Id";
this.ddlCities.DataBind();

你可能感兴趣的:(Invalid)