SitePoint Sponsor |
|
User Tag List
Results 1 to 7 of 7
Hybrid View
-
Oct 8, 2013, 00:08 #1
- Join Date
- Sep 2013
- Posts
- 8
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Classic asp Display Multi selected list box values
Hi
My issues is I am not able to display the multi selected list box values.I could display single value if single value is selected.Please help me on this.
Here is my code:
'To display Client in dropdown
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open Application("conn")
Set oRs = Server.CreateObject("ADODB.Recordset")
dstrSQL="select Name from Client order by Name"
oRs.Open dstrSQL, objConn, 1,3
'Error Handling Part
If Err.Number <> 0 Then
Response.Buffer = True
Response.Redirect "ShowError.asp?ErrNum=" & Err.number & "&ErrSource=" & Err.source & "&ErrDesc=" & Err.description
End If
On Error GoTo 0
'End Error Handling Part
WHILE NOT oRs.EOF
if Request.QueryString("Postback") = "true" and trim(oRs("Name")) = trim(request("ddlClient")) then
ProjClient = ProjClient & "<option selected value=""" & oRs("Name") & """>" & oRs("Name") & "</option>"
ELSE
ProjClient = ProjClient & "<option value=""" & oRs("Name") & """>" & oRs("Name") & "</option>"
END IF
oRs.MoveNext
WEND
oRs.Close
objConn.Close
set oRs = nothing
Set objConn = nothing
-
Oct 10, 2013, 07:39 #2
- Join Date
- Oct 2002
- Location
- Scotland
- Posts
- 3,631
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
You don't show your HTML for the Select list ... have you set that as a Multiselect type?
-
Oct 10, 2013, 22:55 #3
- Join Date
- Sep 2013
- Posts
- 8
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I forgot to mention here the html part of code.
Yes I have used Multipselect type .Here is my html for listbox
<select size="6" name="ddlClient" multiple="multiple">
<%=ProjClient%>
</select>
I am saving the Client as commaseperated values in the db.I have to compare the comma seperated values with each listbox item to select the multiple list items.
-
Oct 11, 2013, 03:10 #4
- Join Date
- Oct 2002
- Location
- Scotland
- Posts
- 3,631
- Mentioned
- 2 Post(s)
- Tagged
- 0 Thread(s)
Ah. I suspect your problem is that you need to split() the oRS("Name") on the comma character. When only one item exists then oRS("Name") equals the value; when more than one exists then oRS("Name") contains a comma:
One name selected - oRS("Name")="Bob"
Two names selected - oRS("Name")="Bob,John"
So your code as it stands will never find a match.
-
Oct 21, 2013, 04:34 #5
- Join Date
- Sep 2013
- Posts
- 8
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
-
Oct 28, 2013, 06:19 #6
- Join Date
- Aug 2011
- Location
- OH, USA
- Posts
- 72
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
did you check you html in browser? just right click and view page source...
it looks like your problem there
if Request.QueryString("Postback") = "true" and trim(oRs("Name")) = trim(request("ddlClient")) then
first part clear and no questions Request.QueryString("Postback") = "true"
second part is a question trim(oRs("Name")) = trim(request("ddlClient")
what you expect to have in trim(request("ddlClient") ? and what should be in trim(oRs("Name"))?
if your select box has <option value = '1' selected>first</option>
<option value = '2'>second</option>
<option value = '3' selected>third</option>
<option value = '4'>forth</option>
in trim(request("ddlClient") you should have 1,3
do you have value of 1,3 in trim(oRs("Name")) - I do not think so... and this is one problem and even of yes which item to mark selected it is no item with value 1,3...
So what you should do split 1,3 in array a= split( trim(request("ddlClient")),",") and search value inside array a
like
for i=0 to ubound(a)
if a(i) = trim(oRs("Name")) then
found = true
end if
next
-
Oct 29, 2013, 04:32 #7
- Join Date
- Sep 2013
- Posts
- 8
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thank you gk53 .Yes I should use split with arrays for desired results.
I finally got my results with following function use
function CheckExistsfunc(namevalue1,Namevalues)
arrClient=split(Namevalues,",")
for i=0 to uBound(arrClient)
if instr(namevalue1,arrClient(i)) > 0 then
CheckExistsfunc = CheckExistsfunc & "<option selected value=""" & arrClient(i) & """>" & arrClient(i) & "</option>"
else
CheckExistsfunc = CheckExistsfunc & "<option value=""" & arrClient(i) & """>" & arrClient(i) & "</option>"
end if
next
end function
and I used this function somthing like below :
<%
Set objConn1 = Server.CreateObject("ADODB.Connection")
objConn1.Open Application("conn")
Set oRs1 = Server.CreateObject("ADODB.Recordset")
dstrSQL="select Name from Client order by Name"
oRs1.Open dstrSQL, objConn1, 1,3
'Error Handling Part
If Err.Number <> 0 Then
Response.Buffer = True
Response.Redirect "ShowError.asp?ErrNum=" & Err.number & "&ErrSource=" & Err.source & "&ErrDesc=" & Err.description
End If
On Error GoTo 0
'End Error Handling Part
dim selectedClient
dim Client
WHILE NOT oRs1.EOF
Client1=Client1 & oRs1("Name") & ","
oRs1.MoveNext
session("Client1")=ClientData
WEND
if request.QueryString("Postback") = "true" then
Client=CheckExistsfunc(request("Client"),session("Client1"))
else
Client=CheckExistsfunc(objRS.fields("Client"),Client1)
end if
oRs1.Close
objConn1.Close
set oRs1 = nothing
Set objConn1 = nothing
%>
<select multiple="multiple" name="Client" size="6">
<%=Client%>
</select>
Bookmarks