I have to move an item from one listbox to another listbox, as the above image indicates.
- > button move one or multiple selected item from listbox1 to listbox2
- >> button move all items from listbox1 to listbox2
- << button delete all items from listbox2
- < button delete selected item from listbox2
- also I have a reset button to clear listbox2
Now the problem occurs when I click the <<, <, and reset button; that is, listbox2 items are not deleted.
protected void btn1_Click(object sender, EventArgs e)
{
lbltext.Visible = false;
if (lstBoxAreaOfResponsibility.SelectedIndex >= 0)
{
foreach (ListItem Item in lstBoxAreaOfResponsibility.Items)
{
if (Item.Selected == true)
{
lstBoxAreaOfResponsibility2.Items.Add(Item);
}
}
}
else
{
lbltext.Visible = true;
lbltext.Text = "Please select atleast one in Area Of Responsibility to move";
}
}
protected void btn2_Click(object sender, EventArgs e)
{
lbltxt.Visible = false;
if (lstBoxAreaOfResponsibility.Items.Count != 0)
{
foreach (ListItem Item in lstBoxAreaOfResponsibility.Items)
{
lstBoxAreaOfResponsibility2.Items.Add(Item);
}
}
else
{
lbltext.Visible = true;
lbltext.Text = "There Is no Item In ListBox 1 to Move";
}
}
protected void btn3_Click(object sender, EventArgs e)
{
lbltext.Visible = false;
if (lstBoxAreaOfResponsibility2.Items.Count != 0)
{
foreach (ListItem Item in lstBoxAreaOfResponsibility2.Items)
{
lstBoxAreaOfResponsibility2.Items.Remove(Item);
}
}
else
{
lbltext.Visible = true;
lbltext.Text = "There Is No Item To Move";
}
}
protected void btn4_Click(object sender, EventArgs e)
{
lbltext.Visible = false;
if (lstBoxAreaOfResponsibility2.SelectedIndex >= 0)
{
foreach (ListItem Item in lstBoxAreaOfResponsibility2.Items)
{
if (Item.Selected == true)
{
lstBoxAreaOfResponsibility2.Items.Remove(Item);
}
}
}
else
{
lbltext.Visible = true;
lbltext.Text = "Please select atleast one in Listbox2 to move";
}
}
after clicking the 3rd and 4th button, it is showing error like
"Collection was modified; enumeration operation may not execute."