473,398 Members | 2,403 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Multiple select listbox values in query

I have two listboxes, the first of which is an autopostback=true that allows
multiple row selection. When I select multiple values (by holding down CTL)
in the first one, it should query the second one. I seem unable to do this
as it only sends back the first item I select whether I have the CTL key
down or not. Upon the return trip, I can select another one, but it still
only sends value for the last one I selected.

-- MY LISTBOX --

<asp:ListBox ID="lbProvinces" runat="server" Font-Size="8pt" width="150px"
EnableViewState="true" OnSelectedIndexChanged="ddlQueryDistricts"
autopostback="true" SelectionMode="Multiple" Rows="3"></asp:ListBox>
-- MY CODE --

Sub ddlQueryDistricts(ByVal sender As Object, ByVal e As EventArgs)

Dim conString As String =
"server=myserver;database=mydb;uid=myuser;pwd=mypw d;"

Dim _sqlStmtLbDistricts As String

If lbProvinces.SelectedItem.Value <> "0" Then
_sqlStmtLbDistricts = "SELECT tblDistrict.clnGUID, tblDistrict.clnName
FROM tblDistrict WHERE tblDistrict.clnProvinceGUID = '" &
lbProvinces.SelectedItem.Value & "' ORDER BY tblDistrict.clnName"
Else
_sqlStmtLbDistricts = "SELECT tblDistrict.clnGUID, tblDistrict.clnName
FROM tblDistrict ORDER BY tblDistrict.clnName"
End If

Dim myDataSetDistricts As New DataSet
Dim myDataAdapterDistricts As New
SqlDataAdapter(_sqlStmtLbDistricts, conString)
myDataAdapterDistricts.Fill(myDataSetDistricts, "DistrictsTmp")
lbDistricts.Datasource = myDataSetDistricts.Tables("DistrictsTmp")
lbDistricts.DataMember = "DistrictsTmp"
lbDistricts.DataTextField = "clnName"
lbDistricts.DataValueField = "clnGUID"
lbDistricts.DataBind()
lbDistricts.Items.Insert(0,New ListItem("--ALL","0"))

End Sub
--
_____
DC G
Nov 18 '05 #1
2 2705
Jos
DC Gringo wrote:
I have two listboxes, the first of which is an autopostback=true that
allows multiple row selection. When I select multiple values (by
holding down CTL) in the first one, it should query the second one.
I seem unable to do this as it only sends back the first item I
select whether I have the CTL key down or not. Upon the return trip,
I can select another one, but it still only sends value for the last
one I selected.


You need to make a loop to find out which items are selected:

Dim li As ListItem
For Each li In lbProvinces.Items
If li.Selected Then
' handle li.Value here
End If
Next li

--

Jos Branders
Nov 18 '05 #2
To autopostback your listbox uses clientside JavaScript, which fires a click
event exactly on the item you just clicked and placing its value as an event
argument. So you can't send more than one value. How can you determine,
clicking on which item script should make a decisiion, that it is time to
collect all selected values and send them back? So simply never use
autopostback on multiselect listboxes :)

"DC Gringo" <dc******@visiontechnology.net> wrote in message
news:OI**************@TK2MSFTNGP12.phx.gbl...
I have two listboxes, the first of which is an autopostback=true that allows multiple row selection. When I select multiple values (by holding down CTL) in the first one, it should query the second one. I seem unable to do this as it only sends back the first item I select whether I have the CTL key
down or not. Upon the return trip, I can select another one, but it still
only sends value for the last one I selected.

-- MY LISTBOX --

<asp:ListBox ID="lbProvinces" runat="server" Font-Size="8pt" width="150px"
EnableViewState="true" OnSelectedIndexChanged="ddlQueryDistricts"
autopostback="true" SelectionMode="Multiple" Rows="3"></asp:ListBox>
-- MY CODE --

Sub ddlQueryDistricts(ByVal sender As Object, ByVal e As EventArgs)

Dim conString As String =
"server=myserver;database=mydb;uid=myuser;pwd=mypw d;"

Dim _sqlStmtLbDistricts As String

If lbProvinces.SelectedItem.Value <> "0" Then
_sqlStmtLbDistricts = "SELECT tblDistrict.clnGUID, tblDistrict.clnName
FROM tblDistrict WHERE tblDistrict.clnProvinceGUID = '" &
lbProvinces.SelectedItem.Value & "' ORDER BY tblDistrict.clnName"
Else
_sqlStmtLbDistricts = "SELECT tblDistrict.clnGUID, tblDistrict.clnName
FROM tblDistrict ORDER BY tblDistrict.clnName"
End If

Dim myDataSetDistricts As New DataSet
Dim myDataAdapterDistricts As New
SqlDataAdapter(_sqlStmtLbDistricts, conString)
myDataAdapterDistricts.Fill(myDataSetDistricts, "DistrictsTmp")
lbDistricts.Datasource = myDataSetDistricts.Tables("DistrictsTmp")
lbDistricts.DataMember = "DistrictsTmp"
lbDistricts.DataTextField = "clnName"
lbDistricts.DataValueField = "clnGUID"
lbDistricts.DataBind()
lbDistricts.Items.Insert(0,New ListItem("--ALL","0"))

End Sub
--
_____
DC G

Nov 18 '05 #3

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

Similar topics

2
by: Jen F. | last post by:
I have inherited a medical database in which there are multiple values stored in a single field (ie. "Current Conditions" field might contain 1-20 different conditions, separated by comma (ie....
0
by: starace | last post by:
I have designed a form that has 5 different list boxes where the selections within each are used as criteria in building a dynamic query. Some boxes are set for multiple selections but these list...
4
by: carl.barrett | last post by:
Hi, I have a list box that displays 2 columns. Behind it sits a query with five columns. These are Column1 (DOB), column2 (a concatenated string of Surname Forname, Title), Column3 (Surname),...
2
by: DC Gringo | last post by:
I have two listboxes, the first of which is an autopostback=true that allows multiple row selection. When I select multiple values (by holding down CTL) in the first one, it should query the...
10
by: ads | last post by:
hi, after binding the dropdownlist to a datasource, ive experience this error "Cannot have multiple items selected in a dropdownlist" after using the code:...
6
by: Dave | last post by:
On my form I have combo boxes. These combo boxes, after updating them, populate respective listboxes that are located below the combo boxes on the same form. I am trying to use a "generate...
2
by: billa856 | last post by:
Hi, My Project is in MS Access. In that I have one form in which I have some textboxes,comboboxes and listboxes. Now when I select value from 1st combobox(CustomerID) then it wil generate list for...
2
by: 6afraidbecause789 | last post by:
Hi - Has anyone ever used toggle buttons to select items in a listbox? I'd like to put about 24 toggle buttons on an unbound form that select or deselect items in a multiple select listbox. I've...
2
AccessIdiot
by: AccessIdiot | last post by:
Apologies if this has been answered before - I searched but couldn't find anything. I have a listbox that is populated with a query. I need to enable the user to select multiple items (simply set...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...

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.