 |
| 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
|
|
|
|

August 14th, 2007, 01:57 AM
|
|
Authorized User
|
|
Join Date: Jul 2007
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

August 14th, 2007, 04:02 AM
|
|
Friend of Wrox
|
|
Join Date: Aug 2004
Posts: 550
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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.
|
|

August 14th, 2007, 04:06 AM
|
|
Authorized User
|
|
Join Date: Jul 2007
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
i can not see "select one" in my drop down list
|
|

August 14th, 2007, 04:14 AM
|
|
Registered User
|
|
Join Date: Aug 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
this is in code behind
ddlCategories.Items.Insert(0, New ListItem("All", 0))
Archu
|
|

August 14th, 2007, 04:39 AM
|
|
Authorized User
|
|
Join Date: Jul 2007
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanks Archu,
but when i select something from my drop down then "select one" increases every time
|
|

August 14th, 2007, 05:03 AM
|
|
Friend of Wrox
|
|
Join Date: Aug 2004
Posts: 550
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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.
|
|

August 14th, 2007, 05:12 AM
|
|
Authorized User
|
|
Join Date: Jul 2007
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
No it has the same problem
|
|

August 14th, 2007, 07:19 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
|
|
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
================================================== =========
|
|

August 14th, 2007, 07:54 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|
|

August 14th, 2007, 09:25 AM
|
|
Friend of Wrox
|
|
Join Date: Aug 2004
Posts: 550
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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.
|
|
 |