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
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAsked:
Who is Participating?
 
CodeCruiserConnect With a Mentor Commented:
You can add a "Please Select..." item at the top of the list. I think DropDownList does not support selectedindex = -1
0
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.