我怎样才能发现这个错误?
DropdownList1.SelectedValue = strText;
这是错误:
DropdownList1的选定值无效,因为它没有出现在项目列表中。
我可以在dropdownlist1中找到类似strText的内容吗?
答案 0 :(得分:3)
您可以使用DropDownList.Items.FindByValue
if( ItemCollection.FindByValue(strText) != null)
{
DropdownList1.SelectedValue = strText;
}
答案 1 :(得分:0)
你可以这样使用
DropdownList1.SelectedIndex =
DropdownList1.Items.IndexOf(DropdownList1.Items.FindByValue(strText));