Solved load DropDownList without selecting one of the items

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

I am using the following code to to populate a DropDownList. How do I avoid the first item being automatically selected?

    Sub Fill_Category1_Combobox()

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

            Dim connection As New SqlConnection(cs1))
            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.Cat1.Items.Add(datareader("Segment 1 Desc"))
                End If
            End While

        Catch ex As Exception
        End Try

    End Sub
Question by:murbro
    LVL 9

    Expert Comment

    Me.SelectedIndex = -1
    LVL 83

    Accepted Solution

    That would be Me.Cat1.SelectedIndex = -1
    LVL 4

    Expert Comment


        In C#, I use RadControls.  When I do RadComboBoxWorkCenter.SelectedIndex = -1, it still selects the first item.  It also did this with the ASP:DropdownList.  What I had been doing before I saw this past was added a new item to the list.

        Using asp controls, I was able to select a blank value by doing this:
    // C# Code.
    this.DropDownList1.Items.Add(new ListItem());
    this.DropDownList1.SelectedValue = "";
    // VB Code.
    Me.DropDownList1.Items.Add(New ListItem())
    Me.DropDownList1.SelectedValue = ""

    Open in new window

    I only tested this in C#!

    Ryan F

    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
    ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    760 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