Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Drop Down List need to add
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Drop Down List need to add "Please Select

 Post Reply Post Reply
Author
BigMeat View Drop Down
Newbie
Newbie


Joined: 29 May 2003
Status: Offline
Points: 9
Post Options Post Options   Thanks (0) Thanks(0)   Quote BigMeat Quote  Post ReplyReply Direct Link To This Post Topic: Drop Down List need to add "Please Select
    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

 

Back to Top
MorningZ View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 May 2002
Location: United States
Status: Offline
Points: 1793
Post Options Post Options   Thanks (0) Thanks(0)   Quote MorningZ Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
BigMeat View Drop Down
Newbie
Newbie


Joined: 29 May 2003
Status: Offline
Points: 9
Post Options Post Options   Thanks (0) Thanks(0)   Quote BigMeat Quote  Post ReplyReply Direct Link To This Post Posted: 30 May 2003 at 3:22am

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

 

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.