Collection was modified; enumeration may not execute error when removing a ListItem from a LIstBox

后端 未结 9 665
抹茶落季
抹茶落季 2020-11-29 12:30

I have two ListBoxes, lstAvailableColors and lstSelectedColors. Between each listbox are two buttons, Add and Remove. When a color or colors is selected in lstAvailableCol

9条回答
  •  鱼传尺愫
    2020-11-29 13:03

    This might help you;

    To Remove:

    protected void btnRemove_Click(object sender, EventArgs e)
    {
        {
            for (int i = 0; i < lstAvailableColors.Items.Count; i++)
            { 
                if(lstAvailableColors.Items[i].Selected)
                    lstAvailableColors.Items.RemoveAt(i);
            }
        }
    }
    

提交回复
热议问题