Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 14th, 2007, 01:57 AM
Authorized User
 
Join Date: Jul 2007
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

 
Old August 14th, 2007, 04:02 AM
Friend of Wrox
 
Join Date: Aug 2004
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.
 
Old August 14th, 2007, 04:06 AM
Authorized User
 
Join Date: Jul 2007
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

 
Old August 14th, 2007, 04:14 AM
Registered User
 
Join Date: Aug 2007
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
 
Old August 14th, 2007, 04:39 AM
Authorized User
 
Join Date: Jul 2007
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

 
Old August 14th, 2007, 05:03 AM
Friend of Wrox
 
Join Date: Aug 2004
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.
 
Old August 14th, 2007, 05:12 AM
Authorized User
 
Join Date: Jul 2007
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

No it has the same problem

 
Old August 14th, 2007, 07:19 AM
Friend of Wrox
 
Join Date: Jun 2003
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
================================================== =========
 
Old August 14th, 2007, 07:54 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 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
 
Old August 14th, 2007, 09:25 AM
Friend of Wrox
 
Join Date: Aug 2004
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.





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 02:58 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.