logo

ASP Multiple-Select List Box Active Server Pages

The user can select more than one row item. The request object streams the selections as comma delimited data. The split function is used to parse the data into an array. The data is associated with an data field and a SQL assembled.

Client

<form name=frmMain action="myServer.asp" method=post>
<select name=lbxReportId MULTIPLE size=5>
<option value="-1">All
<option value="report1">Report1
<option value="report2">Report2
</select>
</form>
</pre>
<h3>Server</h3>
<pre>
iReportId=request("lbxReportId">
sql="select * from my table1, table2"
sql=sql & " where table1.a_field1=table2.b_field2"

if iReportId<>"" and instr(1,iReportId,"-1")=0 then
	arrValues=Split(iReportId,",",-1)
	if ubound(arrValues)=0 then
	sql=sql & " and ucase(trim(field1)) = '" & ucase(trim(iReportId)) & "'"
	else
	sql=sql & "	and "
	sql=sql & " ("
	for i=0 to ubound(arrValues)-1
	if i > 0 then
		sql=sql & " or "
	end if
	sql=sql & " ucase(trim(field1)) = '" & ucase(trim(arrValues(i))) & "'"
	next
	sql=sql & " )"
	end if
end if
s