Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / web / ASP.NET

Remove multiple items from ListBox

5.00/5 (6 votes)
14 May 2010CPOL 13.9K  
public static void RemoveSelected(this ListControl source){ foreach (var item in source.Items.Cast().Where(li => li.Selected).ToList()) source.Items.Remove(item);}protected void btnRemove_Click(object sender, EventArgs e){ lstCity.RemoveSelected();}
public static void RemoveSelected(this ListControl source)
{
    foreach (var item in source.Items.Cast<ListItem>().Where(li => li.Selected).ToList())
        source.Items.Remove(item);
}

protected void btnRemove_Click(object sender, EventArgs e)
{
    lstCity.RemoveSelected();
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)