473,472 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Need selectedvalue of multi list box

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???
Nov 18 '05 #1
2 2132
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?

--
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/3he3b
"bill yeager" <an*******@discussions.microsoft.com> wrote in message
news:6b****************************@phx.gbl...
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???

Nov 18 '05 #2
"bill yeager" <an*******@discussions.microsoft.com> wrote in
news:6b****************************@phx.gbl:

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
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???


Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jeff Thur | last post by:
I am running a SQL Stored Procedure that will give the user a count of how many records are in the database as per certain criteria. I'm using the Execute Scalar Method. I have no problem passing...
4
by: Mantova | last post by:
Maybe it's simple, but I can't get it to work. I'm originally a webdeveloper, and just started to work on a C# windows application. I want a list, something similar to a <select><option> object,...
1
by: Gary Shell | last post by:
I have a pair of combo boxes on a form. Both have their SelectedValue property bound to a column on a table called "Input_Output". One column is called "Class" and the second is called "SubClass"....
7
by: ÀÏÆÅ»³ÔÐ5¸öÔ | last post by:
I want use dropdownlist contral in gridview but have trouble now mycode here: i'm very sorry for my poor english <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"...
4
by: Dooman | last post by:
Hello, I am getting this error when binding a drop down list box to a dataset: The 'SelectedIndex' and 'SelectedValue' attributes are mutually exclusive I have looked at other posts and...
2
by: sree reddy | last post by:
..cs using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls;
2
by: =?Utf-8?B?U3RlcGhlbiBSaXRjaGll?= | last post by:
Hi NET1.1 / Winforms I have a listbox that I am binding to a table via the DataSource property. However I want to be able to programmatically select values in this listbox so I am using the...
0
by: TG | last post by:
Hi! Once again I have hit a brick wall here. I have a combobox in which the user types the server name and then clicks on button 'CONNECT' to populate the next combobox which contains all the...
11
Frinavale
by: Frinavale | last post by:
This question is going to sound a little crazy but.........How do you set the selected item in a ComboBox? I am populating a ComboBox with a bunch of instances of a custom private class: For...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.