SELECT population by ASP

Results 1 to 3 of 3

Thread: SELECT population by ASP

  1. #1
    Cindy Brown Guest

    Default SELECT population by ASP

    I want to create a SELECT drop down box in my web page and have the OPTIONS populated from a SQL table.<BR><BR>I&#039m sure this is a veery basic thing, but I&#039ve been all over the net and can&#039t find out how to do it.<BR><BR>Please be kind, I&#039m an ASP beginner.<BR><BR>Thanks!

  2. #2
    Join Date
    Dec 1969
    Posts
    168

    Default RE: SELECT population by ASP

    &#060;%<BR>sub mk_cbo(name, SQL, field, value)<BR><BR>&#039where name = name of select box<BR>&#039 SQL = SQL statement to send to DB<BR>&#039 field = the field to use for the drop down<BR>&#039 value = the selected item, leave blank for none<BR><BR>&#039Example assumes you are using DNSless connection and <BR>&#039that DB_CONN_STRING has been previously assigned.<BR> <BR>Set cbo_cnn = Server.CreateObject("ADODB.Connection")<BR>cbo_cnn .Open DB_CONN_STRING<BR>Set cbo_rs = Server.CreateObject("ADODB.Recordset")<BR> <BR>cbo_rs.Open SQL, cbo_cnn<BR> <BR>If cbo_rs.BOF And cbo_rs.EOF Then<BR>Response.Write = "Error"<BR>Else<BR>Response.Write("&#060;SELEC T NAME=""" & name & """&#062;" & vbcrlf )<BR><BR>On Error Resume Next<BR>cbo_rs.MoveFirst<BR>do while Not cbo_rs.eof<BR><BR>Response.Write(" &#060;OPTION VALUE=""" & cbo_rs.Fields(field) & """")<BR>if cbo_rs.Fields(field).Value = value then Response.Write(" SELECTED")<BR>Response.Write("&#062;" & cbo_rs.Fields(field) & "&#060;/OPTION&#062;" & vbcrlf)<BR>cbo_rs.MoveNext<BR>loop<BR>Response.Wri te("&#060;/Select&#062;" & vbcrlf)<BR>end if<BR><BR>cbo_rs.Close<BR>set cbo_rs = Nothing<BR>cbo_cnn.Close<BR>set cbo_cnn = Nothing<BR><BR>end sub<BR>%&#062;<BR><BR>&#060;%<BR>How to use<BR><BR>call mk_cbo("dept","Select * from dept;","dept","")<BR>&#039would return a select box of departments<BR><BR>call mk_cbo("dept","Select * from dept;","dept","Managers")<BR>&#039would return a select box of depts w/ Mangers selected.<BR>%&#062;<BR><BR>Hope this helps... Cheers!

  3. #3
    Cindy Brown Guest

    Default RE: SELECT population by ASP

    Thanks! Got it!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •