3

どうすればこのエラーをキャッチできますか?

DropdownList1.SelectedValue = strText;  

これはエラーです:

DropdownList1 の選択された値は、アイテムのリストに表示されないため無効です。

strText が dropdownlist1 に存在するようなものでキャッチできますか?

4

2 に答える 2

3

DropDownList.Items.FindByValueを使用できます

if( ItemCollection.FindByValue(strText) != null)
{
    DropdownList1.SelectedValue = strText;
}
于 2013-03-19T09:00:12.043 に答える
0

このように使用できます

 DropdownList1.SelectedIndex =    
                  DropdownList1.Items.IndexOf(DropdownList1.Items.FindByValue(strText));

ドロップダウンリストのselecteditem
をプログラムで設定する

于 2013-03-19T09:06:03.220 に答える