Print Page | Close Window

Drop Down List need to add "Please Select

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: ASP.NET Discussion
Forum Description: Discussion and chat on ASP.NET related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=3123
Printed Date: 28 March 2026 at 5:58pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Drop Down List need to add "Please Select
Posted By: BigMeat
Subject: Drop Down List need to add "Please Select
Date Posted: 29 May 2003 at 4:25pm

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="ddlStep1" DataTextField="IsTeendesc" DataValueField="IsID" runat="server" AutoPostBack="True"></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

 




Replies:
Posted By: MorningZ
Date Posted: 29 May 2003 at 8:54pm

ddlStep1.DataSource = Cmd.ExecuteReader
ddlStep1.DataBind()
ddlStep1.Items.Insert(0,
New ListItem("-- Please Select --", "0"))

Blue Zero = Position to insert this item, and Dropdowns are zero-based, so zero = first position

Green Text = the Display Value

Bold Text = the Value

 



-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: BigMeat
Date Posted: 30 May 2003 at 3:22am

Thanks Morning Z, that worked like a treat...... Your a STAR!!!

 




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net