473,385 Members | 1,536 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Change dropdownlist default value

dw
Hello, all. I have a dropdownlist with id "lstStates" that shows all the
states. It has two fields -- abbr and state. The "state" field is the
DataTextField. Everytime the page loads, it shows "Alabama" as the default
state. However, I want it to show something like "< please select >" as the
DataTextField, and have Null (or empty string) for the DataValueField for
that default. How can I code this? I tried adding it to the Items property,
but it didn't do anything. Thanks :)
Nov 18 '05 #1
3 1500
Hi,

Try:

ddlMyDropDown.Items.INsert(0,"My first item")

G'Luck
Stu
"dw" <co***************@uncw.edu> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hello, all. I have a dropdownlist with id "lstStates" that shows all the
states. It has two fields -- abbr and state. The "state" field is the
DataTextField. Everytime the page loads, it shows "Alabama" as the default
state. However, I want it to show something like "< please select >" as
the
DataTextField, and have Null (or empty string) for the DataValueField for
that default. How can I code this? I tried adding it to the Items
property,
but it didn't do anything. Thanks :)

Nov 18 '05 #2
try

lstStates.Items.Insert(0, new ListItem("SELECT", ""));

That should do the job. add it after you have done databinding.

HTH

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"dw" <co***************@uncw.edu> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hello, all. I have a dropdownlist with id "lstStates" that shows all the
states. It has two fields -- abbr and state. The "state" field is the
DataTextField. Everytime the page loads, it shows "Alabama" as the default
state. However, I want it to show something like "< please select >" as
the
DataTextField, and have Null (or empty string) for the DataValueField for
that default. How can I code this? I tried adding it to the Items
property,
but it didn't do anything. Thanks :)

Nov 18 '05 #3
dw
Thanks Stu and Hermit. That worked beautifully :)

"Hermit Dave" <he************@CAPS.AND.DOTS.hotmail.com> wrote in message
news:eB**************@TK2MSFTNGP11.phx.gbl...
try

lstStates.Items.Insert(0, new ListItem("SELECT", ""));

That should do the job. add it after you have done databinding.

HTH

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"dw" <co***************@uncw.edu> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hello, all. I have a dropdownlist with id "lstStates" that shows all the
states. It has two fields -- abbr and state. The "state" field is the
DataTextField. Everytime the page loads, it shows "Alabama" as the default state. However, I want it to show something like "< please select >" as
the
DataTextField, and have Null (or empty string) for the DataValueField for that default. How can I code this? I tried adding it to the Items
property,
but it didn't do anything. Thanks :)


Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: DotNetJunky | last post by:
I have built a control that runs an on-line help system. Depending on the category you selected via dropdownlist, it goes out and gets the child subcategories, and if there are any, adds a new...
3
by: Earl Teigrob | last post by:
I want to write a function where I pass in a reference to a dropdownlist and a "match value" and have it returns the index of the dropdownlist item that matchs (or -1 if there is no match) ...
0
by: adam | last post by:
i have custom user control and i'm trying to pass values to custom user control......I need help it seems to me i cannot pass the value to user control from dropdownlist. I have property in a...
7
by: Lastie | last post by:
Hi all, I’ve got a ‘dropdownlist’ web control and I can add ‘listitem’ no problem. I can also bind data from an SQL database fine. My problem is that I want to do both at the same...
2
by: huzz | last post by:
How do i make a dropdownlist selected value based on the value i retrive from the database. Basically i have an edit page and like to display the default value in a dropdown list from the...
8
by: tshad | last post by:
Can you databind a dropdownlist to another dropdownlist? I have 2 identical list. I am getting my data from a DataReader, so as soon as I have bound the first DDL, I can't do it again to the next...
2
by: Atreju | last post by:
Ok I got form within a c sharp page. Situation: On the form I have a drop downliwst and a textbox, the dropdownlist is populated with products and the textbox has a default vale of the product...
2
by: Dabbler | last post by:
In my Registrant FormView I have a DropDownList which loads data from a secondary SqlDataSource "sdsOfficeParks". I need the user to select an office park but save the selected value in the...
1
by: Vagabond Software | last post by:
I'm using a DropDownList in an EditItemTemplate column. This DropDownList will only ever have two dates in it; Now and the default DateTime value (1/1/1900 12:00:00 AM). Somewhere, somehow, the...
4
by: rn5a | last post by:
I am binding a DropDownList with records existing in a database table. I want to add an extra item *SELECT COMPANY* at index 0 so that by default, it gets selected. This is how I tried it but the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.