[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1614
  • Last Modified:

How to select/remove the item from list box (single selection mode)?

I need to move item from listBox1 to listBox2.
Both list boxes are in single selection mode.

Clicks the item1 in ListBox1 and button Add, it works. The item is removed from listBox1 and appears in listBox2.
Clicks the item2 in listBox1 and button  Add, it fails. The error message:

System.Web.HttpException: Cannot have multiple items selected when the SelectionMode is Single.


How do I fix this?
0
chuang4630
Asked:
chuang4630
  • 2
1 Solution
 
REA_ANDREWCommented:
Sorry I found this also I got around it in that code I just posted you with this

    protected void Button2_Click(object sender, EventArgs e)
    {
        ListItem item = ListBox1.SelectedItem;
        ListBox2.Items.Add(item);
        ListBox1.Items.Remove(item);
        ListBox2.Items.FindByText(item.Text).Selected = false;
    }

NOTICE I HAVE ADDED THIS LINE

 ListBox2.Items.FindByText(item.Text).Selected = false; <--------------------------------
0
 
REA_ANDREWCommented:
Do you need anymore assistance with this one?
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now