这样写对马?为什么没有移除
foreach (ListItem item in ListBox1.Items)
{
if (item.Selected == true)
{
string ItemValue = item.Value;
ListBox1.Items.Remove(item.Value);
}
}
ListBox1.DataBind();
foreach (ListItem item in ListBox1.Items)
{
if (item.Selected == true)
{
string ItemValue = item.Value;
ListBox1.Items.Remove(item.Value);
}
}
ListBox1.DataBind();
{
if ....
listbox1.Items.RemoveAt(i)
....
}
1、使用Foreach时不能修改枚举内容,改成for就可以了。
2、DataBind会再次把数据源中的数据填充到ListItem里,你必然看不到Item移除。