473,659 Members | 3,031 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Another Dynamic Droplist question

Hi

I have another drop list question.

I have a table like this:
computer dell
computer ibm
computer hp
laptop toshiba
laptop sony
laptop dell
the first drop list should display only two items:

computer
laptop
and the item selected in the first drop list will generate the 2nd
list, if you select computer then the 2nd list will display:

dell
ibm
hp

once both choices are made they are submitted to a new table, my
problem is this, I can't get it to generate the 2nd list, here's my
code:

<script language="JavaS cript">
<!--
function display(what){
document.getEle mentById(what). selected = true;
}

//-->
</script>
<select name="Family" onchange=submit ()>
<option value=""></option>
<%
'Dimension variables
Dim adoCon 'Holds the Database Connection Object
Dim rsFamily 'Holds the recordset for the records in the database
Dim strSQL 'Holds the SQL query for the database

'Create an ADO connection object
Set adoCon = Server.CreateOb ject("ADODB.Con nection")

'Set an active connection to the Connection object using a DSN-less
connection
adoCon.Open "DRIVER={Micros oft Access Driver (*.mdb)}; DBQ=" &
Server.MapPath( "products.m db")

'Create an ADO recordset object
Set rsFamily = Server.CreateOb ject("ADODB.Rec ordset")

'Initialise the strSQL variable with an SQL statement to query the
database
strSQL = "SELECT DISTINCT Family FROM Model;"

'Open the recordset with the SQL query
rsFamily.Open strSQL, adoCon

'Loop through the recordset
Do While not rsFamily.EOF
%>
<option value="<% Response.Write (rsFamily("Fami ly")) %>">
<% Response.Write (rsFamily("Fami ly")) %>
</option>
<%
'Move to the next record in the recordset
rsFamily.MoveNe xt

Loop

'Reset server objects
rsFamily.Close
Set rsFamily = Nothing

%>
</select>
<br>
<select name="Model">
<option value=""></option>
<%
'Dimension variables
Dim rsModel 'Holds the recordset for the records in the database

'Create an ADO recordset object
Set rsModel = Server.CreateOb ject("ADODB.Rec ordset")

'Initialise the strSQL variable with an SQL statement to query the
database
strSQL = "SELECT DISTINCT Model FROM Model= WHERE Family = '" & Family
& "'"

'Open the recordset with the SQL query
rsModel.Open strSQL, adoCon

'Loop through the recordset
Do While not rsModel.EOF
%>
<option value="<% Response.Write (rsModel("Model ")) %>">
<% Response.Write (rsModel("Model ")) %>
</option>
<%
'Move to the next record in the recordset
rsModel.MoveNex t

Loop

'Reset server objects
rsModel.Close
Set rsModel = Nothing
Set adoCon = Nothing
%>
</select>
the problem is with the line:

strSQL = "SELECT DISTINCT Model FROM Model= WHERE Family = '" & Family
& "'"

if I change it to:

strSQL = "SELECT DISTINCT Model FROM Model= WHERE Family = 'computer'"

then the error goes away, but obviously it won't show the laptops when
selected as it will always show just the computers

what have I done wrong here? can anyone help or provide me with a link
to explain how it should be done?
thanks

Jul 22 '05 #1
4 1717
the first list you can get by doing a SELECT DISTINCT.
For the second list you will have to have the page POST back to the server
and rebuild the page, passing in the first list value

--
Curt Christianson
Site & Scripts: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
<cw****@theatom icmoose.ca> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
Hi

I have another drop list question.

I have a table like this:
computer dell
computer ibm
computer hp
laptop toshiba
laptop sony
laptop dell
the first drop list should display only two items:

computer
laptop
and the item selected in the first drop list will generate the 2nd
list, if you select computer then the 2nd list will display:

dell
ibm
hp

once both choices are made they are submitted to a new table, my
problem is this, I can't get it to generate the 2nd list, here's my
code:

<script language="JavaS cript">
<!--
function display(what){
document.getEle mentById(what). selected = true;
}

//-->
</script>
<select name="Family" onchange=submit ()>
<option value=""></option>
<%
'Dimension variables
Dim adoCon 'Holds the Database Connection Object
Dim rsFamily 'Holds the recordset for the records in the database
Dim strSQL 'Holds the SQL query for the database

'Create an ADO connection object
Set adoCon = Server.CreateOb ject("ADODB.Con nection")

'Set an active connection to the Connection object using a DSN-less
connection
adoCon.Open "DRIVER={Micros oft Access Driver (*.mdb)}; DBQ=" &
Server.MapPath( "products.m db")

'Create an ADO recordset object
Set rsFamily = Server.CreateOb ject("ADODB.Rec ordset")

'Initialise the strSQL variable with an SQL statement to query the
database
strSQL = "SELECT DISTINCT Family FROM Model;"

'Open the recordset with the SQL query
rsFamily.Open strSQL, adoCon

'Loop through the recordset
Do While not rsFamily.EOF
%>
<option value="<% Response.Write (rsFamily("Fami ly")) %>">
<% Response.Write (rsFamily("Fami ly")) %>
</option>
<%
'Move to the next record in the recordset
rsFamily.MoveNe xt

Loop

'Reset server objects
rsFamily.Close
Set rsFamily = Nothing

%>
</select>
<br>
<select name="Model">
<option value=""></option>
<%
'Dimension variables
Dim rsModel 'Holds the recordset for the records in the database

'Create an ADO recordset object
Set rsModel = Server.CreateOb ject("ADODB.Rec ordset")

'Initialise the strSQL variable with an SQL statement to query the
database
strSQL = "SELECT DISTINCT Model FROM Model= WHERE Family = '" & Family
& "'"

'Open the recordset with the SQL query
rsModel.Open strSQL, adoCon

'Loop through the recordset
Do While not rsModel.EOF
%>
<option value="<% Response.Write (rsModel("Model ")) %>">
<% Response.Write (rsModel("Model ")) %>
</option>
<%
'Move to the next record in the recordset
rsModel.MoveNex t

Loop

'Reset server objects
rsModel.Close
Set rsModel = Nothing
Set adoCon = Nothing
%>
</select>
the problem is with the line:

strSQL = "SELECT DISTINCT Model FROM Model= WHERE Family = '" & Family
& "'"

if I change it to:

strSQL = "SELECT DISTINCT Model FROM Model= WHERE Family = 'computer'"

then the error goes away, but obviously it won't show the laptops when
selected as it will always show just the computers

what have I done wrong here? can anyone help or provide me with a link
to explain how it should be done?
thanks

Jul 22 '05 #2
Or, if you don't want to do that (it is by far the most convenient and
robust way, though), you may generate a client-side javascript code based on
your recordsets that adds/removes the appropriate elements in the second
select when the first one changes. But that would really be a pain to write
and maintain.
"Curt_C [MVP]" <software_AT_da rkfalz.com> wrote in message
news:ul******** ******@TK2MSFTN GP10.phx.gbl...
the first list you can get by doing a SELECT DISTINCT.
For the second list you will have to have the page POST back to the server
and rebuild the page, passing in the first list value

--
Curt Christianson
Site & Scripts: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
<cw****@theatom icmoose.ca> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
Hi

I have another drop list question.

I have a table like this:
computer dell
computer ibm
computer hp
laptop toshiba
laptop sony
laptop dell
the first drop list should display only two items:

computer
laptop
and the item selected in the first drop list will generate the 2nd
list, if you select computer then the 2nd list will display:

dell
ibm
hp

once both choices are made they are submitted to a new table, my
problem is this, I can't get it to generate the 2nd list, here's my
code:

<script language="JavaS cript">
<!--
function display(what){
document.getEle mentById(what). selected = true;
}

//-->
</script>
<select name="Family" onchange=submit ()>
<option value=""></option>
<%
'Dimension variables
Dim adoCon 'Holds the Database Connection Object
Dim rsFamily 'Holds the recordset for the records in the database
Dim strSQL 'Holds the SQL query for the database

'Create an ADO connection object
Set adoCon = Server.CreateOb ject("ADODB.Con nection")

'Set an active connection to the Connection object using a DSN-less
connection
adoCon.Open "DRIVER={Micros oft Access Driver (*.mdb)}; DBQ=" &
Server.MapPath( "products.m db")

'Create an ADO recordset object
Set rsFamily = Server.CreateOb ject("ADODB.Rec ordset")

'Initialise the strSQL variable with an SQL statement to query the
database
strSQL = "SELECT DISTINCT Family FROM Model;"

'Open the recordset with the SQL query
rsFamily.Open strSQL, adoCon

'Loop through the recordset
Do While not rsFamily.EOF
%>
<option value="<% Response.Write (rsFamily("Fami ly")) %>">
<% Response.Write (rsFamily("Fami ly")) %>
</option>
<%
'Move to the next record in the recordset
rsFamily.MoveNe xt

Loop

'Reset server objects
rsFamily.Close
Set rsFamily = Nothing

%>
</select>
<br>
<select name="Model">
<option value=""></option>
<%
'Dimension variables
Dim rsModel 'Holds the recordset for the records in the database

'Create an ADO recordset object
Set rsModel = Server.CreateOb ject("ADODB.Rec ordset")

'Initialise the strSQL variable with an SQL statement to query the
database
strSQL = "SELECT DISTINCT Model FROM Model= WHERE Family = '" & Family
& "'"

'Open the recordset with the SQL query
rsModel.Open strSQL, adoCon

'Loop through the recordset
Do While not rsModel.EOF
%>
<option value="<% Response.Write (rsModel("Model ")) %>">
<% Response.Write (rsModel("Model ")) %>
</option>
<%
'Move to the next record in the recordset
rsModel.MoveNex t

Loop

'Reset server objects
rsModel.Close
Set rsModel = Nothing
Set adoCon = Nothing
%>
</select>
the problem is with the line:

strSQL = "SELECT DISTINCT Model FROM Model= WHERE Family = '" & Family
& "'"

if I change it to:

strSQL = "SELECT DISTINCT Model FROM Model= WHERE Family = 'computer'"

then the error goes away, but obviously it won't show the laptops when
selected as it will always show just the computers

what have I done wrong here? can anyone help or provide me with a link
to explain how it should be done?
thanks


Jul 22 '05 #3
Perhaps this may hopefully give you some ideas. It's got a downloadable
sample and does retain values after the post back:

Classic ASP Design Tips - Dependent Listboxes
http://www.bullschmidt.com/devtip-de...tlistboxes.asp

Best regards,
J. Paul Schmidt, Freelance ASP Web Developer
http://www.Bullschmidt.com
ASP Design Tips, ASP Web Database Demo, Free ASP Bar Chart Tool...
*** Sent via Developersdex http://www.developersdex.com ***
Jul 22 '05 #4
That looks like what I am looking for, and it explains what's going on.

I don't think that I need to ask how you found it :)

Thanks

Jul 22 '05 #5

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

Similar topics

3
828
by: Stanley J Mroczek | last post by:
I am trying to load a droplist in VB when the edit is clicked in a datagrid. I tried to use OnDataBinding and loading the droplist in subroutine "loaddd". I get this error Object reference not set to an instance of an object. Here is the code: <asp:TemplateColumn runat="server" HeaderText="Id Type Option" SortExpression="IdTypeOption"> <itemtemplate> <asp:label runat="server" Text='<%# DataBinder.Eval(Container.DataItem,
5
1858
by: C White | last post by:
I'm trying to write an asp script that will create a series of drop lists based on a table like: canada ontario toronto street name link canada ontario toronto road name link canada ontario hamilton road name link canada alberta calgary street name link canada alberta edmonton street name link usa new york buffalo street name link...
3
1104
by: Wardeaux | last post by:
All, looking for sample project on how to add/edit/delete controls from an aspx page at runtime... any pointers is most appreciated!! My controls are simple: Label, Textbox, and DropList... I only want a handful of custom properties to be set for the control... MMTIA wardeaux
4
1376
by: TJS | last post by:
After a post back the selected index should be rest in a droplist to match user's choice, but page always show selected item as first one in the droplist. How can iforce the selected item to be reset I have: Sub Page_Load(s As Object, e As EventArgs) If Page.IsPostBack then
2
1758
by: TJS | last post by:
need help with trying to set selected value on a droplist. -- tried vCaptainID as integer and string , no luck -- tried it in pre render and also after droplist is created , no luck ========= error ====================== Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. Source Error line 392 :
5
2135
by: TJS | last post by:
I need to add validation to drodownlist control but it sends back an error message that says: "System.Web.UI.WebControls.DropDownList' does not allow child controls" the code is : If e.ItemType = ItemType.FieldItem And e.ColumnName = "IDEvent" Then Dim ctlEvent As DropDownList = CType(e.Control, DropDownList) Dim compVal AS CompareValidator = New CompareValidator()
2
1155
by: TJS | last post by:
I have a control, called FieldBuilder, which generates a droplist dynamically for a form. I want to add validation to the droplist thru the 'OnItemCreated' function. i can't seem to get the "controltoValidate" portion correct. Can anyone help ??? -------error msg:--------------- BC30311: Value of type 'System.Web.UI.WebControls.DropDownList' cannot be
0
1072
by: yuchang | last post by:
Hi, I try to use a droplist control to show a list value from Database table "A", and the droplist control is an item of a formview control, its data from Database table "B". My problem is how do I to DataBind the droplist control in Formview control EditItem mode? It means the droplist will show the default value from table B and replace the value after editing the formview by selecting a value from the droplist control.
6
4269
by: shashi shekhar singh | last post by:
Respected Sir, I have to create multiple dynamic dropdownlist boxes and add items dynamically in <asp:table> server control but problem occurs , i.e. except of fist dropdown list no dropdownlist boxes are generating a postback.here is a code . protected void Page_Load(object sender, EventArgs e) { int selected_question = (int)Session; if (!Page.IsPostBack) { display_blueprint(); string...
0
8428
marktang
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...
0
8337
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,...
0
8748
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7359
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6181
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4175
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2754
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
2
1739
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.