dcsimg


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Dependent Dropdown Lists

  1. #1
    Join Date
    Jul 2007
    Posts
    10

    Post Dependent Dropdown Lists

    Hi,

    Im using ASP .NET 1.1 ->Moving to 2.0 and need some help with dependent dropdown lists. I have comboboxes for state,city & area.Based on state,city is populated and the area combobox is populated based on state & city values selected. Im using the autopostback property for doing this,but its not providing any consistent results(I dont know why).If anyone could explain why,it would be of great help.

    Im using an ASP .NET with VB .NET codebehind & Forms Authentication.

    I am a newbie as far as AJAX is concerned.I was thinking of doing the same thing using Javascript,but I wasnt too sure how to go about doing that too.However, AJAX seems to be a good clean way to get things done. Any ideas/nudges in the right direction would be a great help.Ive pasted my code for the population of one of the comboboxes so that you will get some idea of what im implementing. Im using an SQL server 2000 backend.

    Thanks,
    Ray.

    Code:
     Private Sub DropDownList9_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DropDownList9.SelectedIndexChanged
            'Populate The Area List
            Dim a, b As String
            a = DropDownList8.SelectedItem.ToString
            b = DropDownList9.SelectedItem.ToString
            '//declare connection string
            Dim cnString As String = ("Data Source=127.0.0.1; Initial Catalog=Administration" + "User Id=sa;Password=dbpassword")
    
            ' declare Connection, command and other related objects
            Dim conGetData As New SqlConnection(cnString)
            Dim cmdgetdata As New SqlCommand
            Dim drgetdata As SqlDataReader
    
            Try
    
                'open connection
                conGetData.Open()
    
                'prepare connection object to get the data through
                'reader and populate into dataset
                cmdgetdata.CommandType = CommandType.Text
                cmdgetdata.Connection = conGetData
                cmdgetdata.CommandText = "SELECT cityname FROM citylist where StateName=@name and cityname=@name2"
         cmdgetdata.Parameters.Add("@name", SqlDbType.VarChar, 50).Value = a
         cmdgetdata.Parameters.Add("@name2", SqlDbType.VarChar, 50).Value = b
                'read data from command object
                drgetdata = cmdgetdata.ExecuteReader()
    
                If drgetdata.HasRows = True Then
                    While drgetdata.Read()
                        DropDownList10.Items.Add(drgetdata("AreaName").ToString())
                    End While
                Else
                    'close reader and connection
                    drgetdata.Close()
                    conGetData.Close()
                End If
            Catch ex As Exception
                Response.Write(ex.ToString)
            Finally
                'check if connection is still open then attempt to close it
                If conGetData.State = ConnectionState.Open Then
                    conGetData.Close()
                End If
            End Try
        End Sub

  2. #2
    Join Date
    Jul 2007
    Posts
    10
    Never mind . . . .got it using AJAX.

    Here

  3. #3
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,663
    Thanks for the link!

Similar Threads

  1. dropdown list
    By abenitez77 in forum VB Classic
    Replies: 2
    Last Post: 05-08-2014, 11:00 PM
  2. Problem with a Dropdown and paging
    By Matrix.net in forum ASP.NET
    Replies: 1
    Last Post: 10-26-2006, 04:45 AM
  3. Dropdown Issue
    By saikiran_kris in forum Java
    Replies: 2
    Last Post: 03-16-2006, 06:21 PM
  4. Dropdown Issue
    By saikiran_kris in forum Java
    Replies: 0
    Last Post: 03-14-2006, 02:21 PM
  5. Replies: 0
    Last Post: 01-11-2002, 05:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center