PDA

View Full Version : question about list box


gcapp
11-25-2002, 03:27 PM
I have a database with a field for last names. There are a couple hundred in there.

If I want to have a drop-down box that allows a choice to choose the last name beginning with "A, B, C, etc.", how would that be done in asp??

I know how to populate a list box from a database but not with a letter search.

Any help?

Gary

webmarkart
11-25-2002, 03:59 PM
you would do it the same way you are populating it but add the clause:


LNameLetter = Trim(Request("LASTNAMELETTER"))

sql = sql & "WHERE LASTNAME LIKE '%" & LNameLetter & "%' "


LASTNAMELETTER would be the name of the input where the person select the letter

LASTNAME would be the name of the db field that contains the last name

Does that help any?

gcapp
11-25-2002, 08:49 PM
Well your suggestion may be right, but since I am kind of new to asp, I think I have it wrong. I can't get the drop-down menu to pull in just the first letter. I was hoping I could get it to pull in the first letter of the names in the LastName field, but only once. You know, since there are 20 "A's", just one "A" in the drop-down menu.

I think I have something wrong.

This is what I have on the initial page:
<%
dim rsPartner
set rsPartner = Server.CreateObject("ADODB.RecordSet")
LNameLetter = Trim(Request("lastname"))
sqlpartner = "SELECT LastName FROM Partners WHERE LastName LIKE '%" & LNameLetter & "%' "
rsPartner.Open sqlpartner ("provider=microsoft.jet.oledb.4.0;data source="&server.MapPath("/Cattaraugus/youth-bureau/YouthBureau.mdb"))
rsPartner Movefirst
%>

<form name="form1" action="partnerslist.asp" method="post">
<p align="center"><select name="lastname" size="1">
<%
do while NOT rsPartner.EOF
Response.Write("<option value=" & rsPartner("LastName")& "'>")
Response.Write rsPartner("LastName") & "</option>"
rsPartner.MoveNext
loop
rsPartner.Close

set rsPartner=nothing

%>
</select> </p>
<p><input type="submit"></p>
</form>

If someone can help I'd appreciate it.