How do I add a "Select an item..."-choice in a databound dropdown?

  • Thread starter Thread starter Bengt-Erik Eliasson
  • Start date Start date
B

Bengt-Erik Eliasson

Hi!

I want to add a default choice at the top of an DropDownList
(DataValueField="", DataTextField="Select an alarm site..."). How do I do
this with an databound control?
Must I move the result from the SqlCommand to another format (DataView,
DataList or so) and use that as DataSource?
Please attach example or a link to help me in the right direction...

Dim strSQL As String = "SELECT Alarm_site, Alarm_Site_Id FROM Alarms GROUP
BY Alarm_Site_Id ORDER BY Alarm_Site"
Dim objCmd As SqlCommand = New SqlCommand(strSQL, objConn)
objConn.Open()
cboAl_site.DataSource = objCmd.ExecuteReader()
cboAl_site.DataValueField = "Alarm_Site"
cboAl_site.DataTextField = "Alarm_Site_Id"
cboAl_site.DataBind()
objConn.Close()

Thanks in advance Bengt-Erik
 
Hi Bengt-Erik,
I am not the best one who can help you with this, but when someone sees it,
I know that they can help you better if you add this informatation.
I think you can speed up an answer if you give some extra information.
What control do you use.
A dropdown (Html) if so, you better can ask your question in the asp.net
group
A dropdonwlist, used with visual.studio.net VB.net webforms
A combobox, used with visual.studio.net VB.net windowforms
You uses all those three names (the cbo only in you code)
Succes
Cor
 
Hi!

I want to add a default choice at the top of an DropDownList
(DataValueField="", DataTextField="Select an alarm site..."). How do I do
this with an databound control?
Must I move the result from the SqlCommand to another format (DataView,
DataList or so) and use that as DataSource?
Please attach example or a link to help me in the right direction...

Dim strSQL As String = "SELECT Alarm_site, Alarm_Site_Id FROM Alarms GROUP
BY Alarm_Site_Id ORDER BY Alarm_Site"
Dim objCmd As SqlCommand = New SqlCommand(strSQL, objConn)
objConn.Open()
myDropDownList.DataSource = objCmd.ExecuteReader()
myDropDownList.DataValueField = "Alarm_Site"
myDropDownList.DataTextField = "Alarm_Site_Id"
myDropDownList.DataBind()
objConn.Close()

Thanks in advance Bengt-Erik
 
Back
Top