Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Drop Down List need to add "Please Select" 1

Status
Not open for further replies.

IndyGill

Technical User
Jan 15, 2001
191
GB
Hi

I have a dropdown list (ddlStep1) on a form which is populated from a datareader. However I would like the first entry on the dropdown list to say "Please Select" however I am having trouble adding this. The dropdown list does a PostBack which I need, however it will not postback the first value if the first value was from the datareader. So basically I need the first value to say "Please Select" and so the datareader starts from position 2 in the list allowing it to be posted back.

My code is as follows:

Dim Conn As New SqlConnection(ConfigurationSettings.AppSettings("connBSS"))
Dim strSQL As String = "SELECT * FROM Issues WHERE Iss_IsID Is NULL ORDER BY IsTeenDesc"
Dim Cmd As New SqlCommand(strSQL, Conn)
Conn.Open()
ddlStep1.DataSource = Cmd.ExecuteReader
ddlStep1.DataBind()
Conn.Close()

-------

<asp:DropDownList id=&quot;ddlStep1&quot; DataTextField=&quot;IsTeendesc&quot; DataValueField=&quot;IsID&quot; runat=&quot;server&quot; AutoPostBack=&quot;True&quot;></asp:DropDownList>

I thought I could do something like:

ddlStep1.items.insert()

or

ddlStep1.Items.Add()

But this did not work or maybe I am putting it in the wrong section of code, im not sure. Any help would be greatly appreciated.

Thanks in advance




 
You could try creating a list item of (Text) 'Please Select...' / (Value) -1 in design view, then at run-time looping through the data reader, dynamically adding one list item at a time for each row in it...
I do have code for this but it's c#, not VB.


Rhys
Thought out... Maybe,
Opinionated... Probably
But it is only an opinion!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top