How to append a row to an existing drop down list so the user sees None and the selected value is 0 as the first choice.
Posted on 2004-11-11
I am loading a drop down list using the following vb.net procedure. My question is how do I add an entry to the ddlHourDrop below so that the first choice in the list is None in the datatextfield property and 0 in the datavaluefield property without None and 0 actually being a row in the source table PS_Hours (see stored procedure below).
Private Sub HourAdd_ddl()
' This code loads the hour drop-down list used when adding a time record
Dim cmdSelect As SqlCommand
Dim dtrHour As SqlDataReader
cmdSelect = New SqlCommand("PS_HourDrop", conPS)
cmdSelect.CommandType = CommandType.StoredProcedure
dtrHour = cmdSelect.ExecuteReader()
ddlHourDrop.DataSource = dtrHour
ddlHourDrop.DataTextField = "HourDesc"
ddlHourDrop.DataValueField = "Hourid"
The following is the stored procedure that loads the ddl.
CREATE PROCEDURE PS_HourDrop
SELECT HourDesc, Hourid
ORDER BY Hourid