我将列表框的搜索选择标准保存到另一个称为AreasLb的页面上。多个区域可以选择,我只是想设置的用户选择.Selected =真列表框在asp.net中保留多个选定的项目
我认为下面的代码应该工作列表框项目,但事实并非如此,在列表框是没有任何项目选择。
if (s == "Areas")
{
string[] area = nv[s].Substring(0, (nv[s].Length - 1)).Split(';');
int i = 0;
foreach (ListItem item in AreasLb.Items)
{
foreach (var s1 in area)
{
if (s1 == item.Value)
{
AreasLb.Items[i].Selected = true;
}
continue;
}
i = i + 1;
}
continue;
}
你知道你是否在触及'AreasLb.Items [i] .Selected = true;'行吗?一旦你完成了这段代码,你可以检查'AreasLb.Items'并查看数组中的正确项是否设置为true? – 2010-07-30 00:44:26
我打这条线,是的,它被选中并设置为true。我在负载中有一个!Page.IsPostback,所以没有错误。 – asn1981 2010-07-30 01:11:45