foreach (ListItem Item in ClassID.Items)
{
if (Item.Value != "Null")
{
Item.Selected = true;
}
}
//在多个选项的值为“Null”,如何让其不会出错,并选中值为“Null”的第一个选项
在多个选项的值为“Null”,如何让其不会出错,并选中值为“Null”的第一个选项
{
if (Item.Value != "Null")
{
Item.Selected = true;
}
}
//在多个选项的值为“Null”,如何让其不会出错,并选中值为“Null”的第一个选项
在多个选项的值为“Null”,如何让其不会出错,并选中值为“Null”的第一个选项
啊呀,提错了,应该为:在多个选项的值为非“Null”时,如何让其不会出错,并选中值为非“Null”的第一个选项
foreach (ListItem Item in ClassID.Items)
{
if (Item.Value != "Null")
{
Item.Selected = true;
break;
}
}
for (int i = 0; i < ClassID.Items.Count; i++)
{
if (ClassID.Items[i].Value != null)
{
if (index == -1)
{
index = i;
}
}
} ClassID.Items[index].Selected = true;//这里要判断下index是不是等于-1