Results 1 to 9 of 9

Thread: Filling a drop down list from db at IndexChanged

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Nov 2005
    Posts
    259

    Filling a drop down list from db at IndexChanged

    I am attempting to fill a drop down list (from a database) once I choose a value from another drop down list. For instance the first drop down list is named ddlYear. When I select the year I want the next list to fill with all the makes from that year. Here is the code I have so far.
    VB Code:
    1. Protected Sub ddlYear_SelectedIndexChanged( _
    2.         ByVal sender As Object, _
    3.         ByVal e As System.EventArgs) Handles ddlYear.SelectedIndexChanged
    4.  
    5.         If IsPostBack = True Then
    6.             Dim cnn As New OleDbConnection(obConn)
    7.             Dim cmd As New OleDbCommand
    8.             cmd = cnn.CreateCommand
    9.             cmd.Connection = cnn
    10.             Dim da As New OleDbDataAdapter
    11.             Dim dsMake As New DataSet
    12.             Try
    13.                 cnn.Open()
    14.                 cmd.CommandText = "Select Make From tblRecall Where Year = '" & _
    15.                     ddlYear.Text & "'"
    16.                 da.SelectCommand = cmd
    17.                 da.Fill(dsMake, "Makes")
    18.                 ddlMake.DataSource = dsMake.Tables("Makes")
    19.                 ddlMake.DataMember = ("Makes")
    20.             Catch ex As Exception
    21.                 WriteLine(ex.Message)
    22.             Finally
    23.                 cnn.Close()
    24.                 da.Dispose()
    25.             End Try
    26.         End If
    27.     End Sub
    After I select the year nothing at all happens. What am I doing wrong?
    Last edited by FastEddie; Aug 20th, 2006 at 09:55 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width