Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to deleted selected values in listbox in asp.net
Posted

Try this:
C#
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();
}


Get more similar threads here[^]

You can make it using JavaScript also, See here[^]
 
Share this answer
 
v2
C#
List<listitem> itemsToRemove = new List<listitem>();

        foreach (ListItem listItem in ListBox1.Items)
        {
            if (listItem.Selected)
                itemsToRemove.Add(listItem);
        }

        foreach (ListItem listItem in itemsToRemove)
        {
            ListBox1.Items.Remove(listItem);
        }
 
Share this answer
 
v2
Server side: Remove selected Items from Asp.net ListBox[^]
C#
List<listitem> itemsToRemove = new List<listitem>();

        foreach (ListItem listItem in ListBox1.Items)
        {
            if (listItem.Selected)
                itemsToRemove.Add(listItem);
        }

        foreach (ListItem listItem in itemsToRemove)
        {
            ListBox1.Items.Remove(listItem);
        }</listitem></listitem>


Client Side: Move and remove Listbox item to another listbox using jQuery[^]
JavaScript
$("#list1 > option:selected").each(function(){
    $(this).remove();
});


I didn't even had to write it. Googling the question gave me so many links. Please do use Google before you ask!
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900