Need selectedvalue of multi list box

  • Thread starter Thread starter bill yeager
  • Start date Start date
B

bill yeager

I need to get the SelectedValue of each item selected in a
multi-selection listbox. I have the following code, but it
just returns me the SelectedValue of ONLY the first item
selected in the list:


Dim liGroup As ListItem

For Each liGroup In lstGroups.Items

If liGroup.Selected = True Then

blnSelected = True

Dim drGroupBridge As
dsACL.GroupBridgeRow = DsACL1.GroupBridge.NewGroupBridgeRow

drGroupBridge.UserID =
lstGroupUsers.SelectedValue

drGroupBridge.GroupID =
lstGroups.SelectedValue

DsACL1.GroupBridge.Rows.Add
(drGroupBridge)

End If

Next




It does cycle thru the code twice (because I have two
items selected), so it's performing the loop fine.
However, the following line above "drGroupBridge.GroupID =
lstGroups.SelectedValue", is the code I need to check for
the multiple SelectedValues from the lstGroups listbox.
It's only returning the first item selected in the list.

How can I accomplish this? What code am I missing???
 
If i understand you correctly, you have a listbox with multiselect set to
true. You have selected two items out of the list and you are looping thru
the items looking for the selected item value which is set to true. The loop
construct only returns the very first selected item whether or not multiple
items are selected. Is this accurate? This is an ASP.NET listbox?
 
I'm not sure if I understand exactly what you're saying, but it seems to me
that instead of this:

drGroupBridge.GroupID = lstGroups.SelectedValue

your code should read:

drGroupBridge.GroupID = liGroup.Value


Brett
 
Back
Top