Link to home
Start Free TrialLog in
Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on

ASP.net DropDown loading issue

Hi

I am using the following code to add items to a DropDownList.
I use the lines
   Me.Category1.SelectedIndex = -1
            Me.Category1.Text = ""
to unselect the item that is automatically selected but this doesn't seem to work

    Sub Fill_Category1_Combobox()
        Try

            Dim sSQL As String
            sSQL = "SELECT DISTINCT [Segment 1 Desc] FROM Accounting"

            Dim connection As New SqlConnection(Session("MyVar"))
            Dim cmd As New SqlCommand(sSQL, connection)
            connection.Open()
            Dim datareader As SqlDataReader = cmd.ExecuteReader

            Me.Category1.Items.Clear()
            While datareader.Read
                If Not datareader("Segment 1 Desc").Equals(DBNull.Value) Then
                    Me.Category1.Items.Add(datareader("Segment 1 Desc"))
                End If
            End While
            Me.Category1.SelectedIndex = -1
            Me.Category1.Text = ""
            connection.Close()


        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    End Sub
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Murray Brown

ASKER

Thanks