Large DropDown Scrolling List

J

J P Singh

Hi There

We have dropdown on ASP page. The problem is we have about 900 items in the
dropdown. Users scrolling through the list have become very frustrated in
the past.

Can someone suggest if there is another way of implement a dropdown where
the datalist is as big as ours.

I am looking for something like a listbox in VB where you can start typing
the characters and the databelow moves accordingly until you have found what
you want.

Is there anything in ASP/HTML to achieve a similar functionality

thanks
 
B

Bob Barrows

J said:
Hi There

We have dropdown on ASP page. The problem is we have about 900 items
in the dropdown. Users scrolling through the list have become very
frustrated in the past.

Can someone suggest if there is another way of implement a dropdown
where the datalist is as big as ours.

I am looking for something like a listbox in VB where you can start
typing the characters and the databelow moves accordingly until you
have found what you want.

Is there anything in ASP/HTML to achieve a similar functionality
You can do this in client-side code. Go to
http://www.thrasherwebdesign.com/index.asp?pi=links&hp=links.asp and
download my dynamic listbox demo to see one way of doing it. A Google search
should find you other examples.
http://www.learnasp.com/learn/listdynamicmore.asp

Bob Barrows
 
E

Evertjan.

J P Singh wrote on 19 sep 2003 in
microsoft.public.inetserver.asp.general:
We have dropdown on ASP page. The problem is we have about 900 items
in the dropdown. Users scrolling through the list have become very
frustrated in the past.

Can someone suggest if there is another way of implement a dropdown
where the datalist is as big as ours.

I am looking for something like a listbox in VB where you can start
typing the characters and the databelow moves accordingly until you
have found what you want.

Is there anything in ASP/HTML to achieve a similar functionality

Serverside coding cannot help you here so better ask a clientside
[javascript?] ng.

ASP functionality would make a roundtrip to the server on every keypress.

Clientside VBS only helps the IE users, btw.
 
R

Rich

Hello to Bob Barrows,

I went and tried out your ListDemo asp. My proficiency
in asp/vbscript/xml is kind of meager. I got an error
message with your script. I type in server name, ID,
pwrd, and one or two letters to list on and error out. I
placed a bunch of msgbox statements to debug. I can get
between the "1st if" and "2nd If" in sub txtCrit_onkeyup
in your clientside script below. Error message says:

"errorCode = -1072896759
reason=Required white space was missing.

Line =2
linepos = 55
filepos = 56
srcText = <!DOCTYPE HTML PUBLIC "-//WC3//DTD HTML 3.2
Final//EN">"

Is this error in the DTD? Here is your script. It would
be real cool if I could get it to work on my system.

<%@ Language=VBScript %>
<%Response.Buffer=true%>

<HTML>
<HEAD>
<META name="VI60_DefaultClientScript" Content="VBScript">

<META NAME="GENERATOR" Content="Microsoft Visual Studio
6.0">
<SCRIPT ID=clientEventHandlersVBS LANGUAGE=vbscript>
<!--
dim sCurCrit
dim xmldoc
Sub window_onload
dim f
sUser = txtUser
sPwd = txtPwd
sServer = txtServer
if screen.availWidth > 800 then
tblMain.style.fontSize="10pt"
end if
lstTitles.style.visibility="visible"
set xmldoc = nothing
End Sub

Sub txtCrit_onkeyup
dim sOptions, sKey, sCrit, oOption, oNodes,xmlFilt,
oNode,iCritLength

msgbox "entering txtCrit" 'my first error trap

'I have this set to retrieve data when there's a single
character entered.
'With 6000 rows, you may want to increase this to two
characters

sCrit=txtCrit.value
ClearList
sKey = chr(window.event.keyCode)

msgbox "1st if and len of sCrit is " & len(sCrit) & "
and sKey is " & sKey 'my second error trap

if len(sCrit) > 1 then 'change to 2 for 6000 rows
'check to see if someone hit 2 letters so close
together that the elseif code
'never had a chance to execute and create xmlDoc

msgbox "2nd if" 'third error trap
if not xmlDoc is nothing then
set xmlFilt = CreateObject("Microsoft.XMLDOM")
'The following can be replaced by an xslt
transformation if you are so inclined
set xmlFilt.documentelement = xmlFilt.createelement
("rows")
iCritLength = len(sCrit)
for each oNode in xmldoc.documentelement.childnodes
if left(oNode.getattribute
("customerid"),iCritLength) = ucase(sCrit) then
xmlFilt.documentelement.appendchild
oNode.Clonenode(false)
end if
next
msgbox "xmlFilt"
fillList xmlFilt
set xmlFilt = nothing
else
sCurCrit = sCrit
set xmldoc = CreateObject("Microsoft.XMLDOM")
if RetrieveData(sCurCrit,xmldoc) then
msgbox "xmldoc1"
fillList(xmldoc)
end if
end if
elseif len(sCrit) > 0 then 'change to 1 for 6000 rows
if sCrit <> sCurCrit then
sCurCrit = sCrit
if RetrieveData(sCurCrit,xmldoc) then
msgbox "xmldoc2"
fillList(xmldoc)
end if
else
msgbox "xmldoc3"
fillList xmldoc
end if
end if
End Sub
-->
</SCRIPT>
<SCRIPT LANGUAGE=vbscript>
<!--
Sub ClearList
lstTitles.innerHTML=""
End Sub

Sub fillList(pxmlDoc)
'you could have used a data island and bound the
listbox to it, but
'I chose to do it this way
dim oNode
for each oNode in pxmlDoc.documentelement.childnodes
set oOption = document.createElement("OPTION")
oOption.value = oNode.GetAttribute("orderid")
oOption.text = oNode.GetAttribute("customerid") & _
" - " & oNode.GetAttribute("orderid")
lstTitles.options.add oOption
next
end sub

Function RetrieveData(psCrit, pxmlDoc)
dim oHTTP,xPE,bStatus, sUrl
RetrieveData = true
set oHTTP = CreateObject("Microsoft.XMLHTTP")
set pxmlDoc = CreateObject("Microsoft.XMLDOM")
sUrl = "ListDemo_server.asp?P1=" & pscrit & "&User=" &
txtUser.value & _
"&Server=" & txtServer.value & "&PWD=" & txtPwd.value

oHTTP.open "GET",sUrl, false
oHTTP.send
bStatus= pxmlDoc.loadXML(oHTTP.responsetext )
if bStatus = false then
Set xPE = pxmlDoc.parseError
strMessage = "errorCode = " & xPE.errorCode & vbCrLf
strMessage = strMessage & "reason = " & xPE.reason &
vbCrLf
strMessage = strMessage & "Line = " & xPE.Line &
vbCrLf
strMessage = strMessage & "linepos = " & xPE.linepos &
vbCrLf
strMessage = strMessage & "filepos = " & xPE.filepos &
vbCrLf
strMessage = strMessage & "srcText = " & xPE.srcText &
vbCrLf
set xPE = nothing
MsgBox strMessage,,"Retrieving Data"
RetrieveData=false
end if
set oHTTP = nothing
end function
-->
</SCRIPT>
</HEAD>
<BODY bgColor=lightgrey topMargin=2 leftMargin=2>
<DIV id=elHeading><STRONG><FONT color=blue face=Verdana
size=3
style="BORDER-TOP-WIDTH: thin">
Orders Maintenance </FONT></STRONG></DIV>
<P>
<TABLE id=tblMain cellSpacing=1 cellPadding=1 width="75%"
border=1>
<CAPTION>This demo uses the Orders table in the Northwind
database</CAPTION>
<TR>
<TD>SQL Server Name: <INPUT id=txtServer></TD>
<TD> User Name <INPUT id=txtUser></TD>
<TD> Password <INPUT id=txtPwd></TD>
<TR>
<TD>Enter the first few letters of the last name of
the customer id whose data
you wish to view or edit:<BR><INPUT id=txtCrit
name=text1></TD>
<TD colspan=2><SELECT id=lstTitles style="VISIBILITY:
hidden; WIDTH: 252px"
size=8></SELECT>
</TD>
</TR>
</TABLE></P>
</BODY>
</HTML>

Thanks for sharing your script.
Rich
 
B

Bob Barrows

The only way I was able to reproduce your error was by deliberately
imputting some faulty connection data, that caused the connection to SQL
Server to fail. In a real application, I would have put in some
error-handling to take care of this, but since this was a quick demo, I did
not bother.

Where the error-handling has to take place is in the listdemo_server.asp
page <I've snipped some stuff>:

Response.Buffer=true
Response.ContentType="text/xml"
Response.Expires = 0

Dim cnSQL, sConnect
'>>>>
Dim sError

dim sUser,sPwd,sServer,sCriteria

sUser = Request.QueryString("User")
sPwd = Request.QueryString("PWD")
sServer = Request.QueryString("Server")
sConnect = "Provider=SQLOLEDB.1;Password=" & sPwd & ";Persist Security
Info=False;User ID=" & sUser & " ;Initial Catalog=Northwind;Data Source=" &
sServer & ";Application Name=ListDemo"
sCriteria = Request.QueryString("P1")
if len(sCriteria) = 0 then sCriteria= "TR"


set cnSQL = server.CreateObject("ADODB.Connection")
cnSQL.ConnectionString=sConnect
'>>>>here
On Error Resume Next
cnSQL.Open
if err <> 0 then
sError="<error msg=""Connection to SQL Server failed."" errdesc=""" & _
Err.Description & """ connectstring=""" & sConnect & _
""" />"
Response.Write sError
Response.end
end if
On Error GoTo 0

Then, in the RetrieveData function, after the bStatus if statement:

set oErrNode = nothing
set oErrNode = pxmlDoc.selectsinglenode("/error")
if not oErrNode is nothing then
RetrieveData = false
MsgBox oErrNode.getattribute("msg") & vbCrLf & _
oErrNode.getattribute("errdesc") & _
vbCrLf & _
"The connection string was: " & _
vbCrLf & _
oErrNode.getattribute("connectstring")
end if
set oErrNode = nothing


And in the txtCrit_onkeyup sub, there are two places where Retrievedata is
called. You should make them look like this:
if RetrieveData(sCurCrit,xmldoc) then
fillList(xmldoc)
else
txtCrit.value = ""
sCurCrit = ""
txtServer.focus
end if

HTH,
Bob Barrows
 
R

Rich P

Thanks for responding to my question about your listdemo (thanks for
sharing that code). I will try to implement your error handling on
Monday (don't have the server available to me at home). I will respond
back with the results.

Thanks,

Rich
 
R

Rich P

I made the changes per your suggestions in listdemo_server.asp and
listdemo_client.asp. I don't error out now, and I make it all the way
to Sub fillList(pxmlDoc). But I never make it inside the for loop in
txtCrit_onkeyup or the forloop in fillList. Note: using IE6.0.2800

'*******begin code snipet
Sub txtCrit_onkeyup
...
if not xmlDoc is nothing then
set xmlFilt = CreateObject("Microsoft.XMLDOM")
'The following can be replaced by an xslt
'transformation if you are so inclined
set xmlFilt.documentelement = xmlFilt.createelement("rows")
iCritLength = len(sCrit)

'***begin for loop

for each oNode in xmldoc.documentelement.childnodes
if left(oNode.getattribute("customerid"),iCritLength) = ucase(sCrit)
then
xmlFilt.documentelement.appendchild oNode.Clonenode(false)
end if
msgbox "inside oNode for loop" 'just checking if I'm in
next 'for loop - nope!

'***out of for loop

fillList xmlFilt 'xmlFilt has nothing
set xmlFilt = nothing
else
sCurCrit = sCrit

'********end of code snipet

I enter this data on the clientside page:

SqlSrvName cnfrkccmc001
username SA
Password ""
Enter first fiew letters... vi for customer Id vinet.

Do I need to configure anything on IE? I thank you for trying to help
me make your app work on my system. I have made a little progress, just
not quite there. It just seems like a real cool piece of coding.

Rich
 
B

Bob Barrows

I can't troubleshoot this on your machine from here. I've never seen this
code fail so I have no idea what could be going wrong.

There has to be a reason it's not getting into the For loop. You should try
displaying the xmldoc's xml using:

msgbox xmldoc.xml

to make sure it contains some data.


Bob Barrows
 
R

Rich P

msgbox xmldoc.xml returns null. I planted one in Retreive Data, in
txtCrit_onKeyup, fillList. All empty

I was looking at the server side code after I posted my last post and
noticed that you appear to be setting some default password if
len(sPwrd)=0. So I commented that out, and then I got the original
error message again, but now I have some more detail on that.

'***********server side snipet

sUser = Request.QueryString("User")
if len(sUser) = 0 then sUser = "vbact"
sPwd = Request.QueryString("PWD")
'if len(sPwd) = 0 then sPwd="tcabv"
sServer = Request.QueryString("Server")
if len(sServer) = 0 then sServer = "CLNSQLDEV7"
sConnect = "Provider=SQLOLEDB.1;Password=" & sPwd & ";Persist Security
Info=False;User ID=" & sUser & " ;Initial Catalog=Northwind;Data
Source=" & sServer & ";Application Name=ListDemo"
sCriteria = Request.QueryString("P1")
if len(sCriteria) = 0 then sCriteria= "TR"

'**********end serverside snipet

The error is occuring at
'******************************
Function RetrieveData(psCrit, pxmlDoc)
...
strMessage = "errorCode = " & xPE.errorCode & vbCrLf
...
set xPE = nothing
MsgBox strMessage,,"Retrieving Data"
msgbox "after strMessage" '<-----my message box
'<---I get to this one
'************************************************

I fiddled with sPwrd on the server side. If len(sPwrd)>0 then I get an
error message that the SqlSrv connection failed. I have Northwind set to
SA and no password. If I comment out the 'If len(sPwrd) = 0 part then I
get the original error message that I am missing some white space ...
That error occurs in Retrieve Data function. Well, I added an account
to Northwind user shmo, pwrd shmo. Still getting the original error. I
also slapped together a quicky asp to list customerID from Orders to see
if I connect OK to SqlSrv/Northwind. Yeah, worked fine. Here is the
connection string I used in my asp:

oConn.Open("Provider=SQLOLEDB;Data Source=cnFRKccmc001;Initial
Catalog=Northwind;UID=SA;PWD=;");

I tried substituting that in your server side code. Did not make a
difference. Still get same error. Also tried shmo, shmo. same deal.

Yeah, so for me it is always some data entry person that has some
configuration or has entered some combination of data that I have not
accounted for which causes an error. Sorry bout that.

Hope I gave you enough info to see what my problem is without having to
physically be here. Did I mention I am also inside a firewall on a
local intranet, would that make a difference?

I never thought about it, but I am in the same boat of JP (original
poster) where I create a static list from a loop and populate a list
box.
I can't troubleshoot this on your machine from here. I've never seen
this
code fail so I have no idea what could be going wrong.

There has to be a reason it's not getting into the For loop. You should
try
displaying the xmldoc's xml using:

msgbox xmldoc.xml

to make sure it contains some data.

Bob Barrows
<<
Rich
 
B

Bob Barrows

1. It's a bad idea not to assign a password to the SA account. This is how
the Code Red worm was able to spread. Always assign a password for SA, no
matter where the SQL Server or MSDE is installed.

2. Looking at this statement:
oConn.Open("Provider=SQLOLEDB;Data Source=cnFRKccmc001;Initial
Catalog=Northwind;UID=SA;PWD=;");

This looks like a jscript statement. It should look like this in vbscript:
oConn.Open "Provider=SQLOLEDB;Data Source=cnFRKccmc001;" & _
"Initial Catalog=Northwind;UID=SA;PWD="

Again, you should assign a password to SA.

HTH,
Bob Barrows
 
B

Bob Barrows

See inline:

Rich said:
msgbox xmldoc.xml returns null. I planted one in Retreive Data, in
txtCrit_onKeyup, fillList. All empty

I was looking at the server side code after I posted my last post and
noticed that you appear to be setting some default password if
len(sPwrd)=0. So I commented that out, and then I got the original
error message again, but now I have some more detail on that.

'***********server side snipet

sUser = Request.QueryString("User")
if len(sUser) = 0 then sUser = "vbact"
sPwd = Request.QueryString("PWD")
'if len(sPwd) = 0 then sPwd="tcabv"
sServer = Request.QueryString("Server")
if len(sServer) = 0 then sServer = "CLNSQLDEV7"

You should change these defaults to match your situation.

I fiddled with sPwrd on the server side. If len(sPwrd)>0 then I get
an error message that the SqlSrv connection failed. I have Northwind
set to SA and no password. If I comment out the 'If len(sPwrd) = 0
part then I get the original error message that I am missing some
white space ... That error occurs in Retrieve Data function. Well, I
added an account to Northwind user shmo, pwrd shmo.

Did you grant that user rights to the table in Northwind that is being
queried?

Bob Barrows
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top