I try the foll. code---

protected void Button1_Click(object sender, EventArgs e)
{
int i;
for (i = 0; i <= ListBox1.Items.Count - 1; i++)
{
ListBox1.Items.Remove(ListBox1.SelectedValue.ToString());
}


}

But it's not working.

this section for vb.net but this following code will help :

protected void Button1_Click(object sender, EventArgs e)
{
while (listBox1.SelectedItem != null)
   {
      listBox1.Items.Remove(listBox1.SelectedItem);
   }
}

Or you can try this, but this following code not working in .net 1.1 :

public void RemoveItem()
{
   for (int i = 0; i < listBox1.Items.Count; i++)
   {
      if (listBox1.Items[i].Selected)
      {
         listBox1.Items[i].Selected = false;
         listBox1.Items.RemoveAt(i);
         RemoveItem();
      }
   }
}

Also u can try this foll code too :

while (listBox1.SelectedItems.Count > 0)
{
     listBox1.Items.Remove(listBox1.SelectedItems[0]);
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.