Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
| Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old July 2nd, 2005, 01:00 AM
Authorized User
 
Join Date: Aug 2004
Location: , , .
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
Default drop down list values based on another drop down

i have two drop down lists ,one gets its values from sql table using this code:
----------------
If Not Page.IsPostBack Then


            Dim groupidd As String
            groupidd = Session("group")
            Dim MySQL As String = " select [station_id],[station_name],type from station "
            Dim myConn As SqlConnection = New SqlConnection("***")
            Dim objDR As SqlDataReader
            Dim Cmd As New SqlCommand(MySQL, myConn)


            myConn.Open()
            objDR = Cmd.ExecuteReader(System.Data.CommandBehavior.Clos eConnection)
            ddl.DataSource = objDR
            ddl.DataValueField = "station_id"
            ddl.DataTextField = "station_id"
            ddl.DataBind()
            myConn.Close()
-----------------------------------
the other one should get its value from the value of the drop down list item chosen above through this code:
------------------------
Private Sub ddl_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ddl.SelectedIndexChanged
        Dim MySQL As String = "Select distiller_id,distiller_name from distiller inner join station on distiller.station_id=station.station_id and distiller.station_id='& ddl.SelectedValue & ' "
        Dim myConn As SqlConnection = New SqlConnection("***")
        Dim objDR As SqlDataReader
        Dim Cmd As New SqlCommand(MySQL, myConn)
        myConn.Open()
        objDR = Cmd.ExecuteReader(System.Data.CommandBehavior.Clos eConnection)
        ddlcustomer.DataSource = objDR
        ddlcustomer.DataValueField = "distiller_id"
        ddlcustomer.DataTextField = "distiller_name"
        ddlcustomer.DataBind()
        myConn.Close()
    End Sub
--------------------
but that is not happening,do anyone know whats wrong with the code?!!

  #2 (permalink)  
Old July 4th, 2005, 12:24 AM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Make sure you have the AutoPostBack property of the first dropdown set to TRUE.

  #3 (permalink)  
Old July 5th, 2005, 09:46 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Here is your sql query code:
 Dim MySQL As String = "Select distiller_id,distiller_name from distiller inner join station on distiller.station_id=station.station_id and distiller.station_id='& ddl.SelectedValue & ' "

You are telling the database to look for the literal string:
   "& ddl.SelectedValue & "

You are simply missing 2 ":

 Dim MySQL As String = "Select distiller_id,distiller_name from distiller inner join station on distiller.station_id=station.station_id and distiller.station_id='" & ddl.SelectedValue & "' "

-Peter
  #4 (permalink)  
Old July 5th, 2005, 09:57 AM
Friend of Wrox
Points: 4,332, Level: 27
Points: 4,332, Level: 27 Points: 4,332, Level: 27 Points: 4,332, Level: 27
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Excellent eye Peter!



Similar Threads
Thread Thread Starter Forum Replies Last Post
Get data from database based on drop down list sel stapes ASP.NET 2.0 Basics 0 May 22nd, 2008 11:15 AM
Create a drop down list using database values erinrox JSP Basics 1 September 4th, 2007 06:59 AM
Retrive values to Drop down list from DB when Back choudhmh Pro VB.NET 2002/2003 0 January 12th, 2005 10:44 AM
Populating Drop Down based on other drop down jeffbarclay Java Databases 1 November 7th, 2003 12:14 PM
Dynamic Query based on drop-down menu apd8x Javascript 3 June 16th, 2003 05:41 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.