DropDownList“具有一个无效的SelectedValue,因为它在项目列表中不存在” [英] DropDownList “has a SelectedValue which is invalid because it does not exist in the list of items"
本文介绍了DropDownList“具有一个无效的SelectedValue,因为它在项目列表中不存在”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收到一个错误,上面写着:
DropDownList有一个无效的SelectedValue,因为它在项目列表中不存在
我很确定我的DataValueField是正确的。
I''m getting an error with this one that says:
DropDownList "has a SelectedValue which is invalid because it does not exist in the list of items"
I''m quite sure that my DataValueField is correct.
locList.DataSource = ds;
locList.DataTextField = Property.NameColumn;
locList.DataValueField = Property.IdColumn;
locList.DataBind();
推荐答案
locList.DataSource = ds.Tables[0];//assign table not dataset
locList.DataTextField = Property.NameColumn;//make sure you have write column names properly
locList.DataValueField = Property.IdColumn;
locList.DataBind();
快乐编码!
:)
Happy Coding!
:)
使用以下
use following
if (!IsPostBack)
{
locList.DataSource = ds.Tables[0];
locList.DataTextField = Property.NameColumn;
locList.DataValueField = Property.IdColumn;
locList.DataBind();
}
这篇关于DropDownList“具有一个无效的SelectedValue,因为它在项目列表中不存在”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文