473,854 Members | 1,824 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

asp dropdown list with a condition

229 New Member
Hi, Would anyone know how to populate an asp dropdown with a dependant condition.

I need this dropdown to select only artists, ie from the authortwo field where in another field, ie extrathree, the word yes is written.

Expand|Select|Wrap|Line Numbers
  1.   <form method="Post">
  2.       <div>
  3. <select onChange="window.location='' + this.options[this.selectedIndex].value">
  4. <OPTION VALUE = 'artists'>&nbsp;artists</Option>
  5. <OPTION>-----------------------------------------------------</Option>
  6. <%        
  7.     Set oRs=Server.CreateObject("adodb.recordset")
  8.     strSQL = "SELECT DISTINCT AuthorTwo FROM tblGreetingPostCards ORDER BY AuthorTwo"
  9.     oRs.Open strSQL, conn        
  11.     Do while not oRs.EOF
  12.         if Request.Form("GreetingPostCards") = oRs("AuthorTwo") then 'if this is the selected one then display as selected
  13.             Response.Write "<OPTION VALUE = '" & oRS ("AuthorTwo") & "' SELECTED>"
  14.             Response.Write oRs("AuthorTwo") & "</Option>"
  15.             oRs.MoveNext 
  16.     else
  17.             Response.Write "<OPTION VALUE = 'http://www.mysite.com/artgallery.asp?AuthorTwo=" & oRs ("AuthorTwo") & "'>&nbsp;"
  18.             Response.Write oRs("AuthorTwo") & "</Option>"
  19.             oRs.MoveNext 
  20.         end if
  21.     loop        
  22.     %>
  23. </SELECT>
  24. </div>
  25.   </form>
somehow to combine another condition like

Expand|Select|Wrap|Line Numbers
  1.                                     <%
  2. If InStr(rsCard("extrathree"),"yes") > 0 Then
  3. %>
  7. <I><a href="portfol.asp?authortwo=<%=rsCard("authortwo")%>" title="">info&nbsp;</I><a>
  8. <%
  9. Else
  10. %>
  12. <%
  13. End If
  14. %>  
Any help would be great.
Thanks in advance

Feb 9 '08 #1
6 2401
564 Recognized Expert Contributor
Hello fran7,

I am having a hard time understanding what you are trying to do. I really would like to help you out. Can you give a better example on what you are trying to accomplish? The more detail you can provide in this case is better. No need for posting anymore code just what you wish to accomplish in detail.

Here is a stab at trying to answer your questing with what I have read above.

Why don’t you just extend your SQL syntax to add in the condition of the field “extrathree” equaling the word “yes” like this:

Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCT AuthorTwo FROM tblGreetingPostCards WHERE extrathree = ‘yes’ ORDER BY AuthorTwo
Feb 11 '08 #2
346 Recognized Expert Contributor
Also Richard, this really has nothing to do with your question, just a helpful observation. I see that you are trying to categorize things within your drop down like so...

Expand|Select|Wrap|Line Numbers
  1. <OPTION VALUE = 'artists'>&nbsp;artists</Option>
  2. <OPTION>-----------------------------------------------------</Option>

Expand|Select|Wrap|Line Numbers
  1. <select>
  2.    <optgroup label="Artists">
  3.       <option value="Artist1">Artist 1</option>
  4.       <option value="Artist2">Artist 2</option>
  5.       <option value="Artist3">Artist 3</option>
  6.    </optgroup>

Feb 11 '08 #3
229 New Member
Dear Mark, Thanks for the reply.

I hope I can explain better. Basically the dropdown list I have above works fine. But I need it to be populated only by the artists who have " yes" written in another field called "extrathree ".

I have a field called authortwo with all my artists names.
I have another field extrathree where selective artists have a "yes" written. Those without the "yes" at the moment are left blank but I could fill them with "no" for example.

So the problem is to populate the dropdown with only those artists names with "yes" written in the field "extrathree "

Any help would be great.
Feb 12 '08 #4
979 Recognized Expert Contributor
Hi Richard,

I think CroCrew already answered your question didn't he? If you change your SQL string to:

Expand|Select|Wrap|Line Numbers
  1. strSQL = "SELECT DISTINCT AuthorTwo FROM tblGreetingPostCards WHERE extrathree = 'yes' ORDER BY AuthorTwo"
Then only the authors with yes next to their name in the column extrathree will be selected and included in your drop down.

Or is it something else you are after?

Let us know,

Dr B
Feb 12 '08 #5
346 Recognized Expert Contributor
Yes, CroCrew answered your question accurately fran7 - I was merely making a non-related observation ;)

Feb 12 '08 #6
229 New Member
Dear Mark, I did try that before and it didnt work. must have made a typo. I tried again and bobs your uncle. Works great. Thanks again
Feb 12 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

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 dropdown lists. If you change the selection of the left one (e.g. choose parentoption2), it should open up page2.htm in a popup window.
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 set to...it is set to false. Can someone show me what I am doing wrong and tell me the correct way? Thank you. In the page load event, I am doing the following:
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 dropdown list control does not retain its SelectedValue. Unless I read the SelectedValue right after the control has been loaded, populated, and assigned with its original value (and of course that is
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 based on the values selected on both the dropdown lists. But this part is not working. It picks up right value for the first dropdown list and always takes the FIRST value of the second dropdown list. I am not sure how to make it use the selected value...
by: quark1 | last post by:
How do I set the value of ProdQuality_1_hid and change the drop down list on the screeen? I tried sending to the address bar: javascript:setProdQuality_1_hid('Medium') {enter} but I may nedd to send it to the variable "value". Client webform takes
by: Wingot | last post by:
Hey, I have a program I am trying to write using Visual C#, SQL Server 2005/2008, and Visual Studio 2008, and one part of it includes a Schema called Client. Inside this schema, three tables exist named Country, MedicalCondition, and Customer.
by: JJ297 | last post by:
I have a dropdown list populated via a database. I edited the dropdown list to have "select a topic" to always appear when the drop down loads. Now if a user selects a dropdown item it goes into the datagrid fine, but if a user selects "select a topic" I get an error message... Error converting nvarchar to int on adapter.Fill(ds) Here's the code behind can someone please assist? Thanks! Protected Sub...
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 these choices will call another dropdown list box when one of the choices from the first gets selected. (I hope this makes sense) All of this is being done on a single form. I know how to make a (sub) dropdown list not seen before the action...
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 according to selection made in first dropdown list and it will also come from ms-access database.(for example if i am selecting country as india in first dropdown list then in second dropdown list will show states of india) the problem is that i...
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.