Related listboxes and items

M

mohaaron

I have two list boxes which I'm going to use for un-selected items and
selected items. When the page first loads the un-selected items
listbox will get bound to a datasource and the selected items listbox
will also get bound to a datasource of pre-selected items. What I want
to do now is remove the selected items from the un-selected items list
so the items don't show up with both lists. Once a item is added to
the selected list it should not show up in the un-selected items
listbox. I have written so code which I use after both listboxes have
been bound to remove items from the un-selected listbox which are in
the selected listbox but it's not working.

When this method executes I can debug it and see that the count of the
items in the un-selected listbox is being decremented but when the
page displays the items are still in the un-selected listbox. Can
anyone tell me why this might be happening?

private void RemoveItemsFromUnselectdList()
{
// Remove selected fields from non-selected fields box.
foreach (ListItem selectedItem in this.selectedFields.Items)
{
// Find the selected item in the unselectedItems box.
ListItem foundItem =
this.unselectedFields.Items.FindByValue(selectedItem.Value);
// If found.
if (foundItem != null)
{
// Remove it.
this.unselectedFields.Items.Remove(foundItem);
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top