Murray Brown
asked on
ASP.net load DropDownList without selecting one of the items
Hi
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()
Try
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)
connection.Open()
Dim datareader As SqlDataReader = cmd.ExecuteReader
Me.Cat1.Items.Clear()
While datareader.Read
If Not datareader("Segment 1 Desc").Equals(DBNull.Value ) Then
Me.Cat1.Items.Add(dataread er("Segmen t 1 Desc"))
End If
End While
connection.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
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()
Try
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)
connection.Open()
Dim datareader As SqlDataReader = cmd.ExecuteReader
Me.Cat1.Items.Clear()
While datareader.Read
If Not datareader("Segment 1 Desc").Equals(DBNull.Value
Me.Cat1.Items.Add(dataread
End If
End While
connection.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Me.SelectedIndex = -1
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hello,
In C#, I use RadControls. When I do RadComboBoxWorkCenter.Sele ctedIndex = -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:
I only tested this in C#!
Ryan F
In C#, I use RadControls. When I do RadComboBoxWorkCenter.Sele
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 = ""
I only tested this in C#!
Ryan F
ASKER
Thanks