Solved DropDown loading issue

Posted on 2012-08-16
Last Modified: 2012-08-16

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()

            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)
            Dim datareader As SqlDataReader = cmd.ExecuteReader

            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 = ""

        Catch ex As Exception
        End Try

    End Sub
Question by:murbro
    LVL 83

    Accepted Solution

    You can add a "Please Select..." item at the top of the list. I think DropDownList does not support selectedindex = -1

    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    User art_snob ( encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
    The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now