473,573 Members | 3,213 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multiple select listbox values in query

I have two listboxes, the first of which is an autopostback=tr ue 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" OnSelectedIndex Changed="ddlQue ryDistricts"
autopostback="t rue" SelectionMode=" Multiple" Rows="3"></asp:ListBox>
-- MY CODE --

Sub ddlQueryDistric ts(ByVal sender As Object, ByVal e As EventArgs)

Dim conString As String =
"server=myserve r;database=mydb ;uid=myuser;pwd =mypwd;"

Dim _sqlStmtLbDistr icts As String

If lbProvinces.Sel ectedItem.Value <> "0" Then
_sqlStmtLbDistr icts = "SELECT tblDistrict.cln GUID, tblDistrict.cln Name
FROM tblDistrict WHERE tblDistrict.cln ProvinceGUID = '" &
lbProvinces.Sel ectedItem.Value & "' ORDER BY tblDistrict.cln Name"
Else
_sqlStmtLbDistr icts = "SELECT tblDistrict.cln GUID, tblDistrict.cln Name
FROM tblDistrict ORDER BY tblDistrict.cln Name"
End If

Dim myDataSetDistri cts As New DataSet
Dim myDataAdapterDi stricts As New
SqlDataAdapter( _sqlStmtLbDistr icts, conString)
myDataAdapterDi stricts.Fill(my DataSetDistrict s, "DistrictsT mp")
lbDistricts.Dat asource = myDataSetDistri cts.Tables("Dis trictsTmp")
lbDistricts.Dat aMember = "DistrictsT mp"
lbDistricts.Dat aTextField = "clnName"
lbDistricts.Dat aValueField = "clnGUID"
lbDistricts.Dat aBind()
lbDistricts.Ite ms.Insert(0,New ListItem("--ALL","0"))

End Sub
--
_____
DC G
Nov 18 '05 #1
2 2722
Jos
DC Gringo wrote:
I have two listboxes, the first of which is an autopostback=tr ue 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.Ite ms
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******@visio ntechnology.net > wrote in message
news:OI******** ******@TK2MSFTN GP12.phx.gbl...
I have two listboxes, the first of which is an autopostback=tr ue 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" OnSelectedIndex Changed="ddlQue ryDistricts"
autopostback="t rue" SelectionMode=" Multiple" Rows="3"></asp:ListBox>
-- MY CODE --

Sub ddlQueryDistric ts(ByVal sender As Object, ByVal e As EventArgs)

Dim conString As String =
"server=myserve r;database=mydb ;uid=myuser;pwd =mypwd;"

Dim _sqlStmtLbDistr icts As String

If lbProvinces.Sel ectedItem.Value <> "0" Then
_sqlStmtLbDistr icts = "SELECT tblDistrict.cln GUID, tblDistrict.cln Name
FROM tblDistrict WHERE tblDistrict.cln ProvinceGUID = '" &
lbProvinces.Sel ectedItem.Value & "' ORDER BY tblDistrict.cln Name"
Else
_sqlStmtLbDistr icts = "SELECT tblDistrict.cln GUID, tblDistrict.cln Name
FROM tblDistrict ORDER BY tblDistrict.cln Name"
End If

Dim myDataSetDistri cts As New DataSet
Dim myDataAdapterDi stricts As New
SqlDataAdapter( _sqlStmtLbDistr icts, conString)
myDataAdapterDi stricts.Fill(my DataSetDistrict s, "DistrictsT mp")
lbDistricts.Dat asource = myDataSetDistri cts.Tables("Dis trictsTmp")
lbDistricts.Dat aMember = "DistrictsT mp"
lbDistricts.Dat aTextField = "clnName"
lbDistricts.Dat aValueField = "clnGUID"
lbDistricts.Dat aBind()
lbDistricts.Ite ms.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
6550
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. "Heart Disease,Hyper Tyroid,Cancer" etc. I would like to search via combo box for any one or more than one value in this field, ie-what patients have...
0
3491
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 boxes do not necessarily need to have a selection made to be used in the dynamic query. In essence the form can have selections made in all or...
4
5351
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), column4 (Forename) and column5 (title). Columns 3,4 and 5 are not shown in the list box only the first two. DOB Name: &" "&&", "&
2
636
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 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...
10
6361
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: dropdownlist.items.findbyvalue("value").selected = true I didnt specify any selected item in the dropdownlist during binding to the datasource. I use dropdownlist.clearselection() but...
6
9396
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 report" button located on my form to print all of the list box values (that have been updated via selection from combo boxes) from the form to the report....
2
5113
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 1st listbox(PalletNo). Now I want to select miltiple values from that 1st listbox(PalletNo). and based upon this selection from 1st...
2
6936
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 come across a way to set the listbox value to only 1 at a time, but need multiple toggle buttons to be on their corresponding listbox item values...
2
12071
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 listbox Multi Select property to Simple yes?) and then I'd like to commit the choices to a single text field in a table, concatenated and separated by...
0
7741
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8167
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7730
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8028
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5550
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5252
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2164
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1263
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
987
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.