select multiple items in asp.net listbox from code

asp.net, c#

Solution

I figured it out, I was over thinking it... Loop through each list item in the first box and then find each matching result in the second table to be selected.

foreach(ListItem i in ListBoxSourceDetail.Items)
        {
            ListBoxSourceEdit.Items.FindByText(i.ToString()).Selected = true;

        }

Problem

I have two databound listboxes. The first only shows items that have been assigned to my product. The second listbox shows all available items. What I want to do is select all of the items in listbox 2 that list box one contains. For example: ListBox1- Item 1 Item 3 ListBox2- Item 1 (Selected) Item 2 Item 3 (Selected) Code I have: ``` List<string> myList = new List<string>(); foreach(ListItem f in ListBoxSourceDetail.Items) { myList.Add(f.Value); } myList.ForEach(delegate(string n) { ListBoxSourceEdit.SelectedValue = n; }); ```

Original source