Or do this ;) heh:

Class CSelect
  Public Recordset
  Public SelectedValue
  Public ValueField, CaptionField
  Private Function CurrentOption
    If Recordset(ValueField).value = SelectedValue Then
      CurrentOption = "<OPTION SELECTED VALUE=""" & _
         Recordset(ValueField) & """>" & Recordset(CaptionField).Value &
"</OPTION>"
    Else
      CurrentOption = "<OPTION VALUE=""" & Recordset(ValueField) & """>" & _
         Recordset(CaptionField).Value & "</OPTION>
    End If
  End Function
  Public Sub DoListBox(name)
    Response.Write "<SELECT NAME=""" & name & """ SIZE=1>"
    While Not Recodset.EOF
      Response.Write CurrentOption
      Recodset.MoveNext
    Wend
    Response.Write "</SELECT>"
  End Sub
End Class

Put it in an include file and use it everywhere:

Set lbox = New CSelect
Set lbox.Recordset = yourRst
lbox.ValueField = "ID"
lbox.CaptionField = "ItemName"
lbox.SelectedValue = 24 ' some ID comming from request or somewhere else
lbox.DoListBox "SomeName"

And if you have several list boxes no need to recreate the object - just
change the properties
and do it again .. Sorry if there is a typing mistake in the code I wrote it
in the message directly.

Mcihael

-----Original Message-----
From: Ricki Williams [mailto:[EMAIL PROTECTED]]
Sent: Sunday, August 11, 2002 10:21 AM
To: ActiveServerPages
Subject: preselect dropdown


How can I set the initially selected value in a drop down box to a value
from my recordset like I can for a text box?

I can't seem to figure this one out.

ricki


---
You are currently subscribed to activeserverpages as: [EMAIL PROTECTED]
To unsubscribe send a blank email to
%%email.unsub%%


---
You are currently subscribed to activeserverpages as: [email protected]
To unsubscribe send a blank email to [EMAIL PROTECTED]

Reply via email to