Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Multiple select listbox values in query

Reply
Thread Tools

Multiple select listbox values in query

 
 
DC Gringo
Guest
Posts: n/a
 
      04-12-2004
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


 
Reply With Quote
 
 
 
 
Jos
Guest
Posts: n/a
 
      04-12-2004
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


 
Reply With Quote
 
 
 
 
Viktor Jevdokimov
Guest
Posts: n/a
 
      04-14-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Listbox move multiple selected items to second listbox K B ASP .Net 2 01-08-2007 11:16 AM
Pre select multiple listbox items(newbie) Angela ASP .Net 4 06-03-2004 01:46 PM
Multiple select listbox values in query DC Gringo ASP .Net Building Controls 2 04-14-2004 06:28 AM
Multiple select listbox values in query DC Gringo ASP .Net 2 04-14-2004 06:28 AM
select of select box will select multiple in another box palmiere Javascript 1 02-09-2004 01:11 PM



Advertisments