Ask a Question related to ASP Database, Design and Development.
-
Laphan #1
Best way to populate a <SELECT>
Hi All
I've being doing it my own little way for sometime now, but I'm not sure if
its the best.
When I'm doing a recordset for a simple <SELECT> I do it as follows:
<SELECT NAME="FIRSTNAME" SIZE=1>
<%
oRSv.MoveFirst
Do while not oRSv.EOF
Response.Write "<OPTION VALUE='"& oRSv("FIRSTNAME") & "'>" &
oRSv("FIRSTNAME") & "</OPTION>"
oRSv.MoveNext
Loop
%>
</SELECT>
When I'm doing a recordset for a <SELECT> which specifies that one is
selected I do it as follows:
<SELECT NAME="PIC" SIZE=1>
<OPTION
<% IF oRSv("PIC") = "bill" THEN Response.Write "SELECTED " %>
VALUE="bill">Bill</OPTION>
<OPTION
<% IF oRSv("PIC") = "bob" THEN Response.Write "SELECTED " %>
VALUE="bob">Bob</OPTION>
<OPTION
<% IF oRSv("PIC") = "sally" THEN Response.Write "SELECTED " %>
VALUE="sally">Sally</OPTION>
etc....
</SELECT>
Is there a better way of doing the above?
Rgds
Laphan
Laphan Guest
-
Dynamically Populate Multiple Select Boxes
I am trying to develop an application where a user selects the Year, Make and Model of their vehicle. In the past, I had a query that input the... -
How can I select items in a datagrid to populate a second datagrid.
I currently have a datagrid that looks like the following. Sales Table Date Dogs Cats Fish 5/1/2004 4 ... -
Populate select field and textbox dynamically - no refresh
Ive got a db table with the fields Product_Name and Product_Price. I want to display a pulldown containing the product names and display the... -
#25474 [Fbk->Opn]: posting arrays from a select box with multiple select is not working properly
ID: 25474 User updated by: fmuller at cisco dot com Reported By: fmuller at cisco dot com -Status: Feedback... -
SELECT DISTINCT + ORDER BY gives ERROR 145: ORDER BY items mustappear in the select list if SELECT DISTINCT is specified.
Dan, You should be able to do this: SELECT Id, FaxID, ReceivedTime, Pages FROM ( SELECT DISTINCT .Id AS Id, -
Ken Schaefer #2
Re: Best way to populate a <SELECT>
I would use a routine for this:
a) Use .GetRows() to return an array from your recordset. Then pass the
GetRows array into a routine that writes your
<select> element, and selects the appropriate item An example of such a
routine is at the end of this post:
-OR-
b) Use the .Getstring() function to return a string using appropriate
delimiters. Here is an example of using getString() to create a HTML table.
Instead of <td> etc you would use <option> tags:
[url]http://www.juicystudio.com/tutorial/asp/getstring.asp[/url]
Cheers
Ken
'------------------------------------------------------------
' WriteFormSelectList
'------------------------------------------------------------
' Returns HTML for a <select> element
' Accepts strName as string
' Accepts strID as string
' Accepts strHTMLAttributes as string - literal text for any other HTML
attributes
' Accepts form option elements as array
' Accepts array format as integer: 0 = rows/cols, 1 = cols/rows (eg from
getRows)
' Accepts optional text for first <option></option> tag
' Accepts strSelectedValue as option to be selected
'------------------------------------------------------------
Function WriteFormSelectList( _
ByVal strName, _
ByVal strID, _
ByVal strHTMLAttributes, _
ByVal arrOptions, _
ByVal intArrayFormat, _
ByVal strFirstOption, _
ByVal strSelectedValue _
)
Dim i ' array 1st dimension counter
If not isArray(arrOptions) then
Exit Function
End If
WriteFormSelectList = "<select name=""" & strName & """ ID=""" & strID &
""""
If Len(strHTMLAttributes & "") > 0 then
WriteFormSelectList = WriteFormSelectList & " " & strHTMLAttributes & """"
End If
WriteFormSelectList = WriteFormSelectList & ">" & vbCrLf
If Len(strFirstOption) > 0 then
WriteFormSelectList = WriteFormSelectList & strFirstOption & vbCrLf
End If
If intArrayFormat = 0 then
For i = 0 to Ubound(arrOptions, 1)
WriteFormSelectList = WriteFormSelectList & "<option value=""" &
arrOptions(i,0) & """>" & arrOptions(i,1) & "</option>" & vbCrLf
Next
Else
For i = 0 to Ubound(arrOptions, 2)
WriteFormSelectList = WriteFormSelectList & "<option value=""" &
arrOptions(0,i) & """>" & arrOptions(1,i) & "</option>" & vbCrLf
Next
End If
WriteFormSelectList = WriteFormSelectList & "</select>" & vbCrLf
If Len(strSelectedValue & "") > 0 then
WriteFormSelectList = Replace(WriteFormSelectList, "value=""" &
strSelectedValue & """>", "value=""" & strSelectedValue & """ selected>")
End If
End Function
'------------------------------------------------------------
' --- WriteFormSelectList
'------------------------------------------------------------
"Laphan" <news@DoNotEmailMe.co.uk> wrote in message
news:OHEmzHYJEHA.3216@tk2msftngp13.phx.gbl...
: Hi All
:
: I've being doing it my own little way for sometime now, but I'm not sure
if
: its the best.
:
: When I'm doing a recordset for a simple <SELECT> I do it as follows:
:
: <SELECT NAME="FIRSTNAME" SIZE=1>
: <%
: oRSv.MoveFirst
: Do while not oRSv.EOF
: Response.Write "<OPTION VALUE='"& oRSv("FIRSTNAME") & "'>" &
: oRSv("FIRSTNAME") & "</OPTION>"
: oRSv.MoveNext
: Loop
: %>
: </SELECT>
:
: When I'm doing a recordset for a <SELECT> which specifies that one is
: selected I do it as follows:
:
: <SELECT NAME="PIC" SIZE=1>
: <OPTION
: <% IF oRSv("PIC") = "bill" THEN Response.Write "SELECTED " %>
: VALUE="bill">Bill</OPTION>
:
: <OPTION
: <% IF oRSv("PIC") = "bob" THEN Response.Write "SELECTED " %>
: VALUE="bob">Bob</OPTION>
:
: <OPTION
: <% IF oRSv("PIC") = "sally" THEN Response.Write "SELECTED " %>
: VALUE="sally">Sally</OPTION>
:
: etc....
:
: </SELECT>
:
: Is there a better way of doing the above?
:
: Rgds
:
: Laphan
:
:
Ken Schaefer Guest



Reply With Quote

