Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: Populating dropdown list


Message #1 by "Luis Carlos Marinho" <lcdm@u...> on Mon, 25 Jun 2001 19:50:24
Hi,



I need to populate a dropdown list based on the last date I have entered 

in the database.



I have a starting date - suppose itīs January/2000.

Then I need to populate the dropdown list with months between January/2000 

and, say, June/2001 (the last date I have in the database).

This last month will vary based on the last date in the DB.



In the dropdown I must show Jan/2000, Feb/2000... and assign it values 

like 0100, 0200,0300 ...0601





Hope someone can help me with this.



Thanks in advance,



Luis Marinho
Message #2 by "Daniel O'Dorisio" <dodorisio@h...> on Mon, 25 Jun 2001 17:54:51 -0400
umm. ok. do you know how to populate a dropdown list with db values? well

ill tell you anyway. just to make sure.



you do something like:



Dim objRs

Dim ssql

Dim sconn

dim sVal

dim sMonth



ssql = "SELECT <field names> FROM <table name>" ' this will select all the

rows in the table, that way you will get all the months up to the current

one.



conn = "your connstring"

set objrs = Server.Createobject("adodb.recordset")

conn.open ssql, conn, adOpenForwardOnly, adLockReadOnly



Response.Write "<SELECT name=""months"">"



Do until objrs.eof

	sMonth = objRs("month")



	Select Case sMonth

		Case "January"

			sVal = 01

			sVal = sVal & objrs("year")

		Case "Feb...

		'keep the select case going for all 12 months

	End Select



	With Response

		.Write "<option value="""

		.Write sVal

		.Write """>"

		.Write objrs("month")

		.Write "</option>"

	End With

	objrs.movenext

Loop



Response.Write "</SELECT>"



objRs.Close

set objRs = nothing





this sample is dependant on wether or not your db has the month and year in

seperate fields. if they are in the same field then you will need to use

some string manipulation before the select case to get the vaue that is

before the /year.



hope this gives you some ideas



daniel



Daniel O'Dorisio

dodorisio@h...

xxx-xxx-xxxx





-----Original Message-----

From: Luis Carlos Marinho [mailto:lcdm@u...]

Sent: Monday, June 25, 2001 7:50 PM

To: ASP Databases

Subject: [asp_databases] Populating dropdown list





Hi,



I need to populate a dropdown list based on the last date I have entered

in the database.



I have a starting date - suppose itīs January/2000.

Then I need to populate the dropdown list with months between January/2000

and, say, June/2001 (the last date I have in the database).

This last month will vary based on the last date in the DB.



In the dropdown I must show Jan/2000, Feb/2000... and assign it values

like 0100, 0200,0300 ...0601





Hope someone can help me with this.



Thanks in advance,



Luis Marinho


  Return to Index