'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();

posted @ 2009-05-14 00:27  emanlee  阅读(1692)  评论(0编辑  收藏  举报