Murray Brown
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("MyV ar"))
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(dat areader("S egment 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
I am using the following code to add items to a DropDownList.
I use the lines
Me.Category1.SelectedIndex
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("MyV
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
Me.Category1.Items.Add(dat
End If
End While
Me.Category1.SelectedIndex
Me.Category1.Text = ""
connection.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER