某个DropDownList包含A,B,C三个值,
如果我设定DropDownList.SelectedValue="Z"
则会发生「选择的值超出范围」的错误。我如何在运行 DropDownList.SelectedValue="Z" 以前,
先行检测 "Z" 是否包含在 DropDownList 所有的值里面呢﹖
如果我设定DropDownList.SelectedValue="Z"
则会发生「选择的值超出范围」的错误。我如何在运行 DropDownList.SelectedValue="Z" 以前,
先行检测 "Z" 是否包含在 DropDownList 所有的值里面呢﹖
for(int i = 0;i < DropDownList.items.count;i ++)
{
if(DropDownList.items[i].text(或value).Equals("z"))
judge = true;
}
if(judge)
有值的情况
else
无值的情况
for(int i = 0;i < DropDownList.items.count;i ++)
{
if(DropDownList.items[i].text(或value).Equals("z"))
{
judge = true;
return;
}
}
if(judge)
有值的情况
else
无值的情况
if (item == null)//不包含
if (item != null)
{
DropDownList1.SelectedValue="Z";//包含
}
ListItem item = DropDownList1.Items.FindByValue("Z");
ListItem item1 = DropDownList1.Items.FindByText("Z");
if(item != null || item1 != null)
{
DropDownList1.SelectedValue="Z";//包含
}