在程序中使用DropDownList控件,向DropDownList中显示当前一个值,出现异常详细信息: System.ArgumentOutOfRangeException: “DropDownList1”有一个无效 SelectedValue,因为它不在项目列表中。
究其原因,发现要显示的这个值在DropDownList控件已有的ITEM中没有这个值。
我在程序中这样处理的:
string strTemp="aaa";
ListItem item = DropDownList1.Items.FindByValue(strTemp);
if (item != null)
{
DropDownList1.Text = strTemp;
}
strTemp是要显示的字符串。