?
Solved

Multi-Select ListBox Question(s)

Posted on 2005-05-03
5
Medium Priority
?
238 Views
Last Modified: 2010-04-07
First Part is getting the values from the multi-selection listbox. (SelectionMode="Multiple")  I have tried 2 ways to get the selected values from the listbox:

               'First Attempt -> Does not return the selected items
      Dim itm As ListItem
         For Each itm In SubLi.Items
            If itm.Selected Then
               str1 &= itm.Text
            End If
        Next
            
               'Second Attempt -> Does not return the selected items            
      Dim ctr as Integer
                  For ctr=0 to SubLi.Items.Count()-1
                                If SubLi.items(ctr).selected
                          str1 += SubLi.items(ctr).Text
                                end if
                 Next
Each of these 2 ways does not return the selected values - returns nothing.  If I access directly it returns the value str1 = SubLi.items(1).Text but I need to do it in a loop to get all of the selected values. (Assuming this is the only way to get all of the selected items from a multi-listbox)  Would be greatly appreciated if someone can point out where the logic is flawed in these loops, from what I can tell & reading some other solutions these should work.... but for some reason are not returning the selected items.

Part 2 - Set the defaults in the listbox.  How do you set multiple selected items in a list box, ie want to pre-select the first and third items?

0
Comment
Question by:egdigital
  • 2
  • 2
5 Comments
 
LVL 12

Accepted Solution

by:
laotzi2000 earned 1400 total points
ID: 13923425
Part 1:
It seems both should work.
I have a question: do you rebind the listbox on postback in Page_Load?
If that is the case, your selection will be lost on postback.
You should put your code to rebind the listbox inside
if not ispostback then
....
end if
0
 

Author Comment

by:egdigital
ID: 13923492
Laotzi2000
That solved the first problem.. posting note on my laptop now to remember to place binding code inside of 'if not ispostback '.. Would you know how to address the second part of the question?
0
 
LVL 12

Expert Comment

by:laotzi2000
ID: 13923518
Like this?

  ListBox1.Items(0).Selected = True
        ListBox1.Items(2).Selected = True
0
 

Author Comment

by:egdigital
ID: 13923540
Yes, actually I should've tried that out prior to asking.. thanks for the help & prompt answers.
0
 

Expert Comment

by:yaney00074
ID: 14847425
Please I need help on that
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question