[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 426
  • Last Modified:

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
0
Murray Brown
Asked:
Murray Brown
1 Solution
 
CodeCruiserCommented:
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now