Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old August 14th, 2007, 02:57 AM
Authorized User
 
Join Date: Jul 2007
Location: gurgaon, haryana, India.
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default how to add static text in drop down list

Hi, i am trying this


<asp:DropDownList ID="ddlempid" runat="server" Style="z-index: 110; left: 372px;
            position: absolute; top: 31px" AutoPostBack="True" OnSelectedIndexChanged="ddlempid_SelectedIndexChan ged">
            <asp:ListItem Text="select one" Value="select one" Selected=True></asp:ListItem>
        </asp:DropDownList>


but on run time it does not show "select one" how can i do it

plz help

Reply With Quote
  #2 (permalink)  
Old August 14th, 2007, 05:02 AM
Friend of Wrox
Points: 1,935, Level: 17
Points: 1,935, Level: 17 Points: 1,935, Level: 17 Points: 1,935, Level: 17
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2004
Location: United Kingdom
Posts: 550
Thanks: 0
Thanked 1 Time in 1 Post
Default

Well, I copied your code, and it works fine at my end, what do you see in the dropdownlist?

Regards
Mike

Don't expect too much, too soon.
Reply With Quote
  #3 (permalink)  
Old August 14th, 2007, 05:06 AM
Authorized User
 
Join Date: Jul 2007
Location: gurgaon, haryana, India.
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

i can not see "select one" in my drop down list

Reply With Quote
  #4 (permalink)  
Old August 14th, 2007, 05:14 AM
Registered User
 
Join Date: Aug 2007
Location: hyderabad, a.p, India.
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default


      this is in code behind

  ddlCategories.Items.Insert(0, New ListItem("All", 0))

Archu
Reply With Quote
  #5 (permalink)  
Old August 14th, 2007, 05:39 AM
Authorized User
 
Join Date: Jul 2007
Location: gurgaon, haryana, India.
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Archu,
but when i select something from my drop down then "select one" increases every time

Reply With Quote
  #6 (permalink)  
Old August 14th, 2007, 06:03 AM
Friend of Wrox
Points: 1,935, Level: 17
Points: 1,935, Level: 17 Points: 1,935, Level: 17 Points: 1,935, Level: 17
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2004
Location: United Kingdom
Posts: 550
Thanks: 0
Thanked 1 Time in 1 Post
Default

Write in the not postback condition like below:

if (!IsPostback)
{
  ddlCategories.Items.Insert(0, New ListItem("All", 0))
}

Regards
Mike

Don't expect too much, too soon.
Reply With Quote
  #7 (permalink)  
Old August 14th, 2007, 06:12 AM
Authorized User
 
Join Date: Jul 2007
Location: gurgaon, haryana, India.
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

No it has the same problem

Reply With Quote
  #8 (permalink)  
Old August 14th, 2007, 08:19 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there.. where do you add this code?? you have to add this in the page_load event...

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
Reply With Quote
  #9 (permalink)  
Old August 14th, 2007, 08:54 AM
Imar's Avatar
Wrox Author
Points: 71,804, Level: 100
Points: 71,804, Level: 100 Points: 71,804, Level: 100 Points: 71,804, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,050
Thanks: 80
Thanked 1,581 Times in 1,558 Posts
Default

It's much easier than all of this, thanks to ASP.NET 2.0's AppendDataBoundItems property:
Code:
<asp:DropDownList ID="ddlempid" runat="server" AppendDataBoundItems="True">
  <asp:ListItem Text="select one" Value="select one" Selected=True></asp:ListItem>
</asp:DropDownList>
With this setting on, data bound items are appended to the list, rather than overwriting the static items you defined in the markup of the page.

Imar

---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Reply With Quote
  #10 (permalink)  
Old August 14th, 2007, 10:25 AM
Friend of Wrox
Points: 1,935, Level: 17
Points: 1,935, Level: 17 Points: 1,935, Level: 17 Points: 1,935, Level: 17
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2004
Location: United Kingdom
Posts: 550
Thanks: 0
Thanked 1 Time in 1 Post
Default

Thats a great info Imar... frankly I didn't know that... thanx for sharing it with everyone..

Regards
Mike

Don't expect too much, too soon.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Drop down list text value not posting back with co binici ASP.NET 2.0 Basics 0 December 12th, 2006 08:38 PM
how to add tool tips for drop down list ? wlin ASP.NET 2.0 Basics 0 November 20th, 2006 04:12 PM
Static Drop Down Box watkibri Classic ASP Components 1 February 15th, 2006 11:25 PM
Search using drop down list box and a text box tcasp Classic ASP Basics 1 July 31st, 2003 03:58 PM



All times are GMT -4. The time now is 02:29 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.