Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old July 2nd, 2005, 02: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, 01: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, 10: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, 10: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!

 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 12:15 PM
Create a drop down list using database values erinrox JSP Basics 1 September 4th, 2007 07: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 06:41 AM



All times are GMT -4. The time now is 03:44 AM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.