|
 |
asp_web_howto thread: Please Help with multi select listbox
Message #1 by George Lavrov <glavrov@m...> on Sun, 24 Mar 2002 23:49:45 -0800
|
|
Scenario: Returning user logs in and...find that his previously selected
options are totally mixed up...:-). Just kidding, that is exactly what I am
trying to solve.
Here is the question:
How can I populate a listbox from one table AND keep
multiple fields selected according user's information from another table?
My code so far will select only one field which is match for first record
in rsJsSelect.Fields("RegionID"). I know that I suppose to somehow
<Get the value you want to select first. Compare this value to the value of
<each option and add the "selected" attribute to the option if they are
equal...
But I can not really find any examples how to do this and I don't know yet
how to do it by myself... Please help.
If you reply, please, please be kind to include some code
examples...me=newbie very much.
Thanks a lot in advance.
George L.
<%
set rsRegions = Server.CreateObject("ADODB.Recordset")
rsRegions.ActiveConnection = MYDBOCONNECTION
rsRegions.Source = "SELECT RegionID, Description FROM Regions ORDER BY CASE
WHEN RegionID < 9000 THEN 2 ELSE 1 END, RegionID"
rsRegions.CursorType = 0
rsRegions.CursorLocation = 2
rsRegions.LockType = 3
rsRegions.Open()
rsRegions_numRows = 0
%>
<%
set rsJsSelect = Server.CreateObject("ADODB.Recordset")
rsJsSelect.ActiveConnection = MYDBOCONNECTION
rsJsSelect.Source = "SELECT RegionsCandidates.CandidateID,
RegionsCandidates.RegionID FROM RegionsCandidates WHERE
RegionsCandidates.CandidateID=280"
rsJsSelect.CursorType = 0
rsJsSelect.CursorLocation = 2
rsJsSelect.LockType = 3
rsJsSelect.Open()
rsJsSelect_numRows = 0
%>
<html>
<body>
<form>
<select name="Regions" size="5" multiple>
<%
While NOT rsRegions.EOF
If rsRegions.Fields("RegionID")= rsJsSelect.Fields("RegionID") Then %>
<option selected
value="<%=rsRegions.Fields("RegionID")%>"><%=rsRegions.Fields("Description")
%></option>
<%
Else
%>
<option
value="<%=rsRegions.Fields("RegionID")%>"><%=rsRegions.Fields("Description")
%></option>
<%
End If
rsRegions.MoveNext
Wend
If (rsRegions.CursorType > 0) Then
rsRegions.MoveFirst
Else
rsRegions.Requery
End If
%>
</select>
</form>
</body>
</html>
Message #2 by "John P. Miller" <jpmiller@a...> on Mon, 25 Mar 2002 09:20:05 -0500
|
|
Here's what I do (There are more intelligent people on this list,
however...):
<option> <%= rsOne(0) %> </option>
<% Do while not rsTwo.EOF %>
<option> <%= rsTwo(0) %> </option>
<% rsTwo.MoveNext
Loop %></select>
Where rsOne is the selected value (what the user previously selected) and
rsTwo is the dynamic select criteria.
HTH,
John Miller
jpmiller@a...
----- Original Message -----
From: "George Lavrov" <glavrov@m...>
To: "ASP Web HowTo" <asp_web_howto@p...>
Sent: Monday, March 25, 2002 2:49 AM
Subject: [asp_web_howto] Please Help with multi select listbox
> Scenario: Returning user logs in and...find that his previously selected
> options are totally mixed up...:-). Just kidding, that is exactly what I
am
> trying to solve.
> Here is the question:
> How can I populate a listbox from one table AND keep
> multiple fields selected according user's information from another table?
> My code so far will select only one field which is match for first record
> in rsJsSelect.Fields("RegionID"). I know that I suppose to somehow
>
> <Get the value you want to select first. Compare this value to the value
of
> <each option and add the "selected" attribute to the option if they are
> equal...
>
> But I can not really find any examples how to do this and I don't know yet
> how to do it by myself... Please help.
> If you reply, please, please be kind to include some code
> examples...me=newbie very much.
>
> Thanks a lot in advance.
> George L.
>
> <%
> set rsRegions = Server.CreateObject("ADODB.Recordset")
> rsRegions.ActiveConnection = MYDBOCONNECTION
> rsRegions.Source = "SELECT RegionID, Description FROM Regions ORDER BY
CASE
> WHEN RegionID < 9000 THEN 2 ELSE 1 END, RegionID"
> rsRegions.CursorType = 0
> rsRegions.CursorLocation = 2
> rsRegions.LockType = 3
> rsRegions.Open()
> rsRegions_numRows = 0
> %>
> <%
> set rsJsSelect = Server.CreateObject("ADODB.Recordset")
> rsJsSelect.ActiveConnection = MYDBOCONNECTION
> rsJsSelect.Source = "SELECT RegionsCandidates.CandidateID,
> RegionsCandidates.RegionID FROM RegionsCandidates WHERE
> RegionsCandidates.CandidateID=280"
> rsJsSelect.CursorType = 0
> rsJsSelect.CursorLocation = 2
> rsJsSelect.LockType = 3
> rsJsSelect.Open()
> rsJsSelect_numRows = 0
> %>
>
> <html>
> <body>
> <form>
> <select name="Regions" size="5" multiple>
> <%
> While NOT rsRegions.EOF
> If rsRegions.Fields("RegionID")= rsJsSelect.Fields("RegionID") Then %>
>
> <option selected
>
value="<%=rsRegions.Fields("RegionID")%>"><%=rsRegions.Fields("Description")
> %></option>
>
> <%
> Else
> %>
> <option
>
value="<%=rsRegions.Fields("RegionID")%>"><%=rsRegions.Fields("Description")
> %></option>
> <%
> End If
> rsRegions.MoveNext
> Wend
> If (rsRegions.CursorType > 0) Then
> rsRegions.MoveFirst
> Else
> rsRegions.Requery
> End If
> %>
> </select>
> </form>
> </body>
> </html>
>
>
>
>
> ---
>
> Improve your web design skills with these new books from Glasshaus.
>
> Usable Web Menus
> http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=nosim/theprogramme
> r-20
> Constructing Accessible Web Sites
> http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=nosim/theprogramme
> r-20
> Practical JavaScript for the Usable Web
> http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=nosim/theprogramme
> r-20
Message #3 by George Lavrov <glavrov@m...> on Mon, 25 Mar 2002 10:54:36 -0800
|
|
Thanks John, but this is not working.
Any time I'll do something like <%= rsOne(0) %>, I will get this error:
Error Type:
Microsoft VBScript runtime (0x800A01C2)
Wrong number of arguments or invalid property assignment: '[object]'
Besides, I can't really do <option> <%= rsOne(0) %> </option> cause all
names of my fields in listbox coming from rsTwo and rsOne contains only IDs
(numbers).
George L.
-----Original Message-----
From: John P. Miller [mailto:jpmiller@a...]
Sent: Monday, March 25, 2002 6:20 AM
To: ASP Web HowTo
Subject: [asp_web_howto] Re: Please Help with multi select listbox
Here's what I do (There are more intelligent people on this list,
however...):
<option> <%= rsOne(0) %> </option>
<% Do while not rsTwo.EOF %>
<option> <%= rsTwo(0) %> </option>
<% rsTwo.MoveNext
Loop %></select>
Where rsOne is the selected value (what the user previously selected) and
rsTwo is the dynamic select criteria.
HTH,
John Miller
jpmiller@a...
----- Original Message -----
From: "George Lavrov" <glavrov@m...>
To: "ASP Web HowTo" <asp_web_howto@p...>
Sent: Monday, March 25, 2002 2:49 AM
Subject: [asp_web_howto] Please Help with multi select listbox
> Scenario: Returning user logs in and...find that his previously
> selected options are totally mixed up...:-). Just kidding, that is
> exactly what I
am
> trying to solve.
> Here is the question:
> How can I populate a listbox from one table AND keep
> multiple fields selected according user's information from another
> table? My code so far will select only one field which is match for
> first record in rsJsSelect.Fields("RegionID"). I know that I suppose
> to somehow
>
> <Get the value you want to select first. Compare this value to the
> value
of
> <each option and add the "selected" attribute to the option if they
> are equal...
>
> But I can not really find any examples how to do this and I don't know
> yet how to do it by myself... Please help. If you reply, please,
> please be kind to include some code examples...me=newbie very much.
>
> Thanks a lot in advance.
> George L.
>
> <%
> set rsRegions = Server.CreateObject("ADODB.Recordset")
> rsRegions.ActiveConnection = MYDBOCONNECTION
> rsRegions.Source = "SELECT RegionID, Description FROM Regions ORDER BY
CASE
> WHEN RegionID < 9000 THEN 2 ELSE 1 END, RegionID" rsRegions.CursorType
> = 0 rsRegions.CursorLocation = 2
> rsRegions.LockType = 3
> rsRegions.Open()
> rsRegions_numRows = 0
> %>
> <%
> set rsJsSelect = Server.CreateObject("ADODB.Recordset")
> rsJsSelect.ActiveConnection = MYDBOCONNECTION
> rsJsSelect.Source = "SELECT RegionsCandidates.CandidateID,
> RegionsCandidates.RegionID FROM RegionsCandidates WHERE
> RegionsCandidates.CandidateID=280"
> rsJsSelect.CursorType = 0
> rsJsSelect.CursorLocation = 2
> rsJsSelect.LockType = 3
> rsJsSelect.Open()
> rsJsSelect_numRows = 0
> %>
>
> <html>
> <body>
> <form>
> <select name="Regions" size="5" multiple>
> <%
> While NOT rsRegions.EOF
> If rsRegions.Fields("RegionID")= rsJsSelect.Fields("RegionID") Then %>
>
> <option selected
>
value="<%=rsRegions.Fields("RegionID")%>"><%=rsRegions.Fields("Description")
> %></option>
>
> <%
> Else
> %>
> <option
>
value="<%=rsRegions.Fields("RegionID")%>"><%=rsRegions.Fields("Description")
> %></option>
> <%
> End If
> rsRegions.MoveNext
> Wend
> If (rsRegions.CursorType > 0) Then
> rsRegions.MoveFirst
> Else
> rsRegions.Requery
> End If
> %>
> </select>
> </form>
> </body>
> </html>
>
>
>
>
> ---
>
> Improve your web design skills with these new books from Glasshaus.
>
> Usable Web Menus
> http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=nosim/theprogram
> me
> r-20
> Constructing Accessible Web Sites
> http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=nosim/theprogramme
> r-20
> Practical JavaScript for the Usable Web
> http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=nosim/theprogramme
> r-20
---
Improve your web design skills with these new books from Glasshaus.
Usable Web Menus
http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=nosim/theprogramme
r-20
Constructing Accessible Web Sites
http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=nosim/theprogramme
r-20
Practical JavaScript for the Usable Web
http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=nosim/theprogramme
r-20
Message #4 by George Lavrov <glavrov@m...> on Tue, 26 Mar 2002 11:11:18 -0800
|
|
With help of my friend, here is code which seems to work. Note change in
setting one of the cursors type to static, anything else and error will
result:
<%
set rsRegions = Server.CreateObject("ADODB.Recordset")
rsRegions.ActiveConnection = MYDBOCONNECTION
rsRegions.Source = "SELECT RegionID, Description FROM Regions ORDER BY CASE
WHEN RegionID < 9000 THEN 2 ELSE 1 END, RegionID"
rsRegions.CursorType = 0
rsRegions.CursorLocation = 2
rsRegions.LockType = 3
rsRegions.Open()
rsRegions_numRows = 0
%>
<%
set rsJsSelect = Server.CreateObject("ADODB.Recordset")
rsJsSelect.ActiveConnection = MYDBOCONNECTION
rsJsSelect.Source = "SELECT RegionsCandidates.CandidateID,
RegionsCandidates.RegionID FROM RegionsCandidates WHERE
RegionsCandidates.CandidateID=280"
rsJsSelect.CursorType = adOpenStatic
rsJsSelect.Open()
rsJsSelect_numRows = 0
%>
<html>
<body>
<form>
<select name="Regions" size="5" multiple>
<%
rsRegions.MoveFirst
Do While NOT rsRegions.EOF
rsJsSelect.MoveFirst
rsJsSelect.Find "RegionID =" & rsRegions.Fields("RegionID")
If Not rsJsSelect.EOF Then
%>
<option selected
value="<%=rsRegions.Fields("RegionID")%>"><%=rsRegions.Fields("Description")
%></option>
<%
Else
%>
<option
value="<%=rsRegions.Fields("RegionID")%>"><%=rsRegions.Fields("Description")
%></option>
<%
End If
rsRegions.MoveNext
Loop
%>
</select>
</form>
</body>
</html>
<%
rsJsSelect.Close()
Set rsJsSelect=Nothing
%>
<%
rsRegions.Close()
Set rsRegions=Nothing
%>
-----Original Message-----
From: George Lavrov [mailto:glavrov@m...]
Sent: Monday, March 25, 2002 10:55 AM
To: ASP Web HowTo
Subject: [asp_web_howto] Re: Please Help with multi select listbox
Thanks John, but this is not working.
Any time I'll do something like <%= rsOne(0) %>, I will get this error:
Error Type: Microsoft VBScript runtime (0x800A01C2) Wrong number of
arguments or invalid property assignment: '[object]'
Besides, I can't really do <option> <%= rsOne(0) %> </option> cause all
names of my fields in listbox coming from rsTwo and rsOne contains only IDs
(numbers).
George L.
-----Original Message-----
From: John P. Miller [mailto:jpmiller@a...]
Sent: Monday, March 25, 2002 6:20 AM
To: ASP Web HowTo
Subject: [asp_web_howto] Re: Please Help with multi select listbox
Here's what I do (There are more intelligent people on this list,
however...):
<option> <%= rsOne(0) %> </option>
<% Do while not rsTwo.EOF %>
<option> <%= rsTwo(0) %> </option>
<% rsTwo.MoveNext
Loop %></select>
Where rsOne is the selected value (what the user previously selected) and
rsTwo is the dynamic select criteria.
HTH,
John Miller
jpmiller@a...
----- Original Message -----
From: "George Lavrov" <glavrov@m...>
To: "ASP Web HowTo" <asp_web_howto@p...>
Sent: Monday, March 25, 2002 2:49 AM
Subject: [asp_web_howto] Please Help with multi select listbox
> Scenario: Returning user logs in and...find that his previously
> selected options are totally mixed up...:-). Just kidding, that is
> exactly what I
am
> trying to solve.
> Here is the question:
> How can I populate a listbox from one table AND keep
> multiple fields selected according user's information from another
> table? My code so far will select only one field which is match for
> first record in rsJsSelect.Fields("RegionID"). I know that I suppose
> to somehow
>
> <Get the value you want to select first. Compare this value to the
> value
of
> <each option and add the "selected" attribute to the option if they
> are equal...
>
> But I can not really find any examples how to do this and I don't know
> yet how to do it by myself... Please help. If you reply, please,
> please be kind to include some code examples...me=newbie very much.
>
> Thanks a lot in advance.
> George L.
>
> <%
> set rsRegions = Server.CreateObject("ADODB.Recordset")
> rsRegions.ActiveConnection = MYDBOCONNECTION
> rsRegions.Source = "SELECT RegionID, Description FROM Regions ORDER BY
CASE
> WHEN RegionID < 9000 THEN 2 ELSE 1 END, RegionID" rsRegions.CursorType
> = 0 rsRegions.CursorLocation = 2
> rsRegions.LockType = 3
> rsRegions.Open()
> rsRegions_numRows = 0
> %>
> <%
> set rsJsSelect = Server.CreateObject("ADODB.Recordset")
> rsJsSelect.ActiveConnection = MYDBOCONNECTION
> rsJsSelect.Source = "SELECT RegionsCandidates.CandidateID,
> RegionsCandidates.RegionID FROM RegionsCandidates WHERE
> RegionsCandidates.CandidateID=280"
> rsJsSelect.CursorType = 0
> rsJsSelect.CursorLocation = 2
> rsJsSelect.LockType = 3
> rsJsSelect.Open()
> rsJsSelect_numRows = 0
> %>
>
> <html>
> <body>
> <form>
> <select name="Regions" size="5" multiple>
> <%
> While NOT rsRegions.EOF
> If rsRegions.Fields("RegionID")= rsJsSelect.Fields("RegionID") Then %>
>
> <option selected
>
value="<%=rsRegions.Fields("RegionID")%>"><%=rsRegions.Fields("Description")
> %></option>
>
> <%
> Else
> %>
> <option
>
value="<%=rsRegions.Fields("RegionID")%>"><%=rsRegions.Fields("Description")
> %></option>
> <%
> End If
> rsRegions.MoveNext
> Wend
> If (rsRegions.CursorType > 0) Then
> rsRegions.MoveFirst
> Else
> rsRegions.Requery
> End If
> %>
> </select>
> </form>
> </body>
> </html>
>
>
>
>
> ---
>
> Improve your web design skills with these new books from Glasshaus.
>
> Usable Web Menus
> http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=nosim/theprogram
> me
> r-20
> Constructing Accessible Web Sites
> http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=nosim/theprogramme
> r-20
> Practical JavaScript for the Usable Web
> http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=nosim/theprogramme
> r-20
---
Improve your web design skills with these new books from Glasshaus.
Usable Web Menus
http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=nosim/theprogramme
r-20
Constructing Accessible Web Sites
http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=nosim/theprogramme
r-20
Practical JavaScript for the Usable Web
http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=nosim/theprogramme
r-20
---
Improve your web design skills with these new books from Glasshaus.
Usable Web Menus
http://www.amazon.com/exec/obidos/ASIN/1904151027/ref=nosim/theprogramme
r-20
Constructing Accessible Web Sites
http://www.amazon.com/exec/obidos/ASIN/1904151000/ref=nosim/theprogramme
r-20
Practical JavaScript for the Usable Web
http://www.amazon.com/exec/obidos/ASIN/1904151051/ref=nosim/theprogramme
r-20
Message #5 by "Ken Schaefer" <ken@a...> on Wed, 27 Mar 2002 12:55:31 +1100
|
|
Create two arrays: one to hold the master list of all the items in the
select list, one to hold the options the user has already selected (eg using
GetRows).
You then create the select list by looping through the items in the master
items array For each item, you check to see if there is a match in the other
array (by doing a loop through the user's selection array). If there is a
match, write "selected" into the <option> tag.
Cheers
Ken
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: "George Lavrov" <glavrov@m...>
Subject: [asp_web_howto] Please Help with multi select listbox
: Scenario: Returning user logs in and...find that his previously selected
: options are totally mixed up...:-). Just kidding, that is exactly what I
am
: trying to solve.
: Here is the question:
: How can I populate a listbox from one table AND keep
: multiple fields selected according user's information from another table?
: My code so far will select only one field which is match for first record
: in rsJsSelect.Fields("RegionID"). I know that I suppose to somehow
:
: <Get the value you want to select first. Compare this value to the value
of
: <each option and add the "selected" attribute to the option if they are
: equal...
:
: But I can not really find any examples how to do this and I don't know yet
: how to do it by myself... Please help.
: If you reply, please, please be kind to include some code
: examples...me=newbie very much.
:
: Thanks a lot in advance.
: George L.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.wrox.com.
|
|
 |