I have three listboxes. the selected items from one listbox(lst1) should be populated in another listbox(lst2) on click of add button and accordingly the third listbox(lst3) needs to be populated with values from db as per the selected values in lst2. theres no selecteditems property i m using ms visual studio2005 similar logic need to be used on click of remove button
1
votes
2 Answers
0
votes
public static class Extensions
{
public static IEnumerable<ListItem> GetSelectedItems(
this ListItemCollection items)
{
return items.OfType<ListItem>().Where(item => item.Selected);
}
}
On button click
------------------
var selected = lstFirst.Items.GetSelectedItems();
foreach (var li in selected)
{
if (!lstSecond.Items.Contains(li))
{
ListItem newItem = new ListItem(li.Text, li.Value);
lstSecond.Items.Add(newItem);
}
}