472,355 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,355 software developers and data experts.

Dropdown list in ASP

This is probably really stupid, but I cannot figure it out, and none of
the references I've found seem quite right for what I'm trying to do.
How do I do the below, but have the option values and Option Choice
Text Description pull from the db instead of requiring manual data
entry?

<option value="1" <%If (Not isNull((RS.Fields.Item("ID").Value))) Then
If ("1" =CStr((RS.Fields.Item("ID").Value))) Then
Response.Write("SELECTED") : Response.Write("")%>>Option Choice Text
Description</option>

Can anybody point me to some resources for this? Thanks in advance.

Oct 20 '06 #1
1 1473
ms****@soon.com wrote:
This is probably really stupid, but I cannot figure it out, and none
of the references I've found seem quite right for what I'm trying to
do. How do I do the below, but have the option values and Option
Choice Text Description pull from the db instead of requiring manual
data entry?

<option value="1" <%If (Not isNull((RS.Fields.Item("ID").Value))) Then
If ("1" =CStr((RS.Fields.Item("ID").Value))) Then
Response.Write("SELECTED") :
Why could ID be Null? Why don't you exclude Null ID's in the query's
WHERE clause?

It looks like you really want to compare ID to Value, correct? If ID =
Value, then make the option selected, right?
Response.Write("")%>>Option Choice Text
Description</option>
You neglected to show us the sql statement that produced that recordset.
As a result I'm not going to be able to give you the most efficient
solution, which involves using GetRows. Instead, I'm going to resort to
an inefficient recordset loop and, as you did not provide the name of
the field that contains the option text, I'm going to invent a field
name - OptionText. Substitute the actual name of the field
Try thinking of the problem this way: you're just creating a string of
text that happens to contain html. It's not a mystery.

My preference is to build the options totally in server-side code,
storing the string in a variable and then response.writing the variable
into the select tag. Something like;

<%
....
dim options
options = "<option"
do until rs.eof
options=options & " value = """ & rs("Value") & """"
if rs("ID") = rs("Value") then
options=options & " SELECTED"
end if
options=options & ">" & rs("OptionText") & "<option"
rs.movenext
loop
rs.close: set rs=nothing
'close and destroy the connection here also
options=left(options, len(options) - 7)
%>
<html><body>
<select>
<%=options%>
</select>
</body></html>

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Oct 20 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Joseph Barron | last post by:
Here is a SIMPLE problem that I'm trying to solve. It works in Netscape 6.2, but IE6 gives ""No such interface supported." Below are page1.htm and page2.htm . In page1.htm, there are two...
6
by: Mark | last post by:
I have two dropdown lists. Both have autopostback set to true. In both dropdowns, when you select an item from the list, it redirects to the Value property of the dropdown. Nothing fancy. ...
4
by: Paul | last post by:
I have a dropdown list box and a button on a web form, the autopost back is false for the dropdown list box and button. When the button is pushed the selection in the dropdownlist box is lost,...
2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
5
by: jung_h_park | last post by:
From: jung_h_park@yahoo.com Newsgroups: microsoft.public.dotnet.framework.aspnet Subject: Dropdown List not retaining its SelectedValue Date: Mon, 26 Jun 2006 21:02:57 -0700 Hello, My...
3
by: er1 | last post by:
Hi all, I have created a double dropdown list. Based on the first list selection, second list populates (this works fine). I have a submit button, which when clicked should run a select query...
6
by: yasodhai | last post by:
Hi, I used a dropdown control which is binded to a datagrid control. I passed the values to the dropdownlist from the database using a function as follows in the aspx itself. <asp:DropDownList...
0
by: Andrus | last post by:
I'm using WinForms DataGridView I need to make dropdown list wider that grid column width. I tried the following code, but dropdown list widht is the same as column width. How to increase...
3
by: fish919 | last post by:
Hello All, I am creating a date base in access. I want to create a dropdown list box that is connected to another dropdown list box. You start with a dropdown list that has 5 choices and each of...
5
by: abhi3211 | last post by:
i am using java inside java script page. in that page i want to use two dropdown list. in first dropdown list i am getting data from ms-access database. in second dropdown list i want to get data...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
1
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. header("Location:".$urlback); Is this the right layout the...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.