The method is GetSelectedIndices().
Here is an example. Say you have an ASP.NET ListBox control something like this.
|
You can get all selected items in your code using the following code snippet.
ListBox1.GetSelectedIndices();GetSelectedIndices gives us the index of all selected items in the ListBox. Note: The output is in array collections.

Suthish NairPosted Aug 29, 2010, 3:28 PM
While using GetSelectedIndices(), duplicate values in ListBox is not supported. You can add them, but the framework always uses only the first matching list item value. You can test the code by adding duplicate items in ListBox.
Suthish NairPosted Aug 29, 2010, 3:16 PM
GetSelectedIndices() - Gets the array of index values for currently selected items in the ListBox control. We can avoid looping the whole items to find the selected item. If we need the selected items for further use, of course we need to loop the records. :-)
Mahesh ChandPosted Aug 29, 2010, 12:32 PM
Even though you get index of all selected items, you still have to loop through to get all items. Don't you?