Hi I am using the following code to populate text boxes based on a drop down list index change event

Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As WinControls.UI.Data.PositionChangedEventArgs) Handles DropDownList1.SelectedIndexChanged

        Dim connString As String = My.Settings.strConn
        Dim conn As New SqlConnection(connString)
        Try
            conn.Open()
            Dim qry As String = "select * from property where propRef='" + RadDropDownList1.SelectedText + "'"

            Dim cmd As New SqlCommand(qry, conn)

            Dim dr As SqlDataReader = cmd.ExecuteReader()
            If dr.Read() Then
                TextBoxHouseNo.Text = dr(3)
                TextBoxStreet.Text = dr(4)
                TextBoxCity.Text = dr(5)
                TextBoxPostCode.Text = dr(6)
                TextBoxRent.Text = dr(12)
            End If
            dr.Close()
        Catch ex As Exception

        Finally

            conn.Close()
        End Try

    End Sub

The code works until it gets to the last item if there is only one item in the dropdown box it does not populate the text boxes, if I loop through the code it is going to the droplist index change but it goes from dr.Read() and just jumps to dr.close() without populating the text boxes?

any suggestions

tahnks

M

What will be selected text ur getting when only one item in textbox?
Just take that value and try to run on database check to see if there are records for it.

Dim qry As String = "select * from property where propRef='" + RadDropDownList1.SelectedText + "'"

Chang it to

Dim qry As String = "select * from property where propRef='" + RadDropDownList1.Text + "'"

If any other problem . let me know....

Thanks for the response but that didn't resolve my problem

I am using this to populate the dropdownlist

Dim connString As String = My.Settings.strConn
        Dim conn As New SqlConnection(connString)
        Try
            conn.Open()
            Dim strSQL As String = "SELECT * FROM property WHERE (available = 1)"
            Dim da As New SqlDataAdapter(strSQL, conn)
            Dim ds As New DataSet
            da.Fill(ds, "property")

            With DropDownList1
                .DataSource = ds.Tables("property")
                .DisplayMember = "propRef"
                .ValueMember = "p_id"
                .SelectedIndex = 0

            End With
        Catch ex As Exception

        Finally
            'conn.Dispose()
            conn.Close()
        End Try

I have tried putting this code on the page load event and on button click event either works the same way.

Ok I am able to get it to work using the GotFocus event it is not populating by itself I still have to click the dropDownList to get it to populate the textBoxes it seems a little strange that it does not do this on an event?

Yes on page load

Me.TenantTableAdapter.Fill(Me.PropertyDataSet.tenant)
        'TODO: This line of code loads data into the 'PropertyDataSet._property' table. You can move, or remove it, as needed.
        Me.PropertyTableAdapter.Fill(Me.PropertyDataSet._property)
This article has been dead for over six months. Start a new discussion instead.