要求:
1、在网页上有一个DropDownList1和一个Button1控件;
2、DropDownList1控件加载一个列表(从数据库中连接);
3、从DropDownList1列表中选择一个值后,按确定按钮Button1;
3、根据选择值进行程序运算,运算后从DropDownList1列表中删除选择的值,重新创建列表。
问题:
运行过程中出现提示:“DropDownList1”有一个无效 SelectedValue,因为它不在项目列表中。不知为何?如何解决这个问题?
1、在网页上有一个DropDownList1和一个Button1控件;
2、DropDownList1控件加载一个列表(从数据库中连接);
3、从DropDownList1列表中选择一个值后,按确定按钮Button1;
3、根据选择值进行程序运算,运算后从DropDownList1列表中删除选择的值,重新创建列表。
问题:
运行过程中出现提示:“DropDownList1”有一个无效 SelectedValue,因为它不在项目列表中。不知为何?如何解决这个问题?
{
if (!IsPostBack)
{
ddlCmpBind();
}
} private void ddlDataBind()
{
ddlCmp.Items.Clear();
B_CompanyMst bllCmp = new B_CompanyMst();
ddlCmp.DataSource = bllCmp.GetAllCmp();
ddlCmp.DataValueField = "CmpID";
ddlCmp.DataTextField = "CmpName";
ddlCmp.DataBind();
ddlCmp.Items.Insert(0, "---请选择---");
}
{
if (!IsPostBack)
{
ddlDataBind();
}
} private void ddlDataBind()
{
ddlCmp.Items.Clear();
B_CompanyMst bllCmp = new B_CompanyMst();
ddlCmp.DataSource = bllCmp.GetAllCmp();
ddlCmp.DataValueField = "CmpID";
ddlCmp.DataTextField = "CmpName";
ddlCmp.DataBind();
ddlCmp.Items.Insert(0, "---请选择---");
}
DropDownList1.Items.Remove(DropDownList1.Text)
用这个语句可以满足我的要求,意思是:删除选择项。
再次感谢大家!!