Select multiple items in asp.net list from code

I have two data lists. The first shows only those objects that have been assigned to my product. The second list shows all available items. What I want to do is select all the items in list 2, which contains the list.

For example:
ListBox1-
Item 1
Item 3

ListBox2-
Item 1 (selected)
Item 2
Item 3 (selected)

The code I have is:

List<string> myList = new List<string>();
            foreach(ListItem f in ListBoxSourceDetail.Items)
            {
                myList.Add(f.Value);
            }
            myList.ForEach(delegate(string n)
            {
                ListBoxSourceEdit.SelectedValue = n;
            });
+3
source share
1 answer

, ... , , .

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

        }
+4

Source: https://habr.com/ru/post/1779300/


All Articles