我怎样才能捕捉到这个错误?
DropdownList1.SelectedValue = strText;  
这是错误:
DropdownList1 的选定值无效,因为它未出现在项目列表中。
我可以用 dropdownlist1 中的 strText 之类的东西来捕捉它吗?
我怎样才能捕捉到这个错误?
DropdownList1.SelectedValue = strText;  
这是错误:
DropdownList1 的选定值无效,因为它未出现在项目列表中。
我可以用 dropdownlist1 中的 strText 之类的东西来捕捉它吗?
您可以使用DropDownList.Items.FindByValue
if( ItemCollection.FindByValue(strText) != null)
{
    DropdownList1.SelectedValue = strText;
}
    你可以这样使用
 DropdownList1.SelectedIndex =    
                  DropdownList1.Items.IndexOf(DropdownList1.Items.FindByValue(strText));
以编程方式
设置下拉列表选定项