我绑定了一个下拉列表,这是我的代码:(DataLayer)
string countrySQL = "SELECT * From Country";
string[] param = { };
object[] paramVal = { };
return ClassDBQuery.ExecDataReader(countrySQL, param, paramVal);
void GetCountry()
{
DataTable DTcountry = new DataTable();
DTcountry = ClassMerchant.GetCountry();
ddlC.DataSource = DTcountry;
ddlC.DataTextField = "CountryName";
ddlC.DataValueField = "CountryID";
ddlC.DataBind();
} // end GetCountry
当我包含时,.datavaluefield = "CountryID"
我收到此消息
selectedvalue which is invalid because it does not exist in the list of items dropdownlist
但是,当我删除.datavaluefield
代码的其他部分时,我得到了错误,因为我没有得到 ,而是CountryID
得到了CountryName
并强制它从字符串转换为整数。但是这个数据绑定代码在我的注册页面中工作正常。如何使我的数据绑定(下拉列表)工作?