473,472 Members | 2,224 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How do you set DataBound Dropdownlist to "Choose"?

GS
Hi,

I have dropdown list bound to a Table, I don't want dropdown list to select first row from a table but rather to display "Choose" and when user clicks it then to display available values.
How can I do that?
Feb 14 '06 #1
5 1523
If using asp.net 2.0, the listbox has a property called
AppendDataBoundItems, set that property to true. You then go ahead and
use the designer to add a Choose to the listbox. After the databind
you should still see Choose first.

For 1.1, after to databind the items in the listbox in code you then
just add a new listitem to the dropdown in code as well.

Feb 14 '06 #2
GS,
The easiest and least error-prone way is to add a row to the DataTable
before databinding "Please Choose" with the InsertAt method, then bind to the
control.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"GS" wrote:
Hi,

I have dropdown list bound to a Table, I don't want dropdown list to select first row from a table but rather to display "Choose" and when user clicks it then to display available values.
How can I do that?

Feb 14 '06 #3
GS
Excellent that's what I needed (I use ASP.NET 2.0).
Now comes second problem since I bound GridView to DropDownList control and
it errors out now becouse DropDownList contains invalid data (manual input).
"tdavisjr" <td******@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
If using asp.net 2.0, the listbox has a property called
AppendDataBoundItems, set that property to true. You then go ahead and
use the designer to add a Choose to the listbox. After the databind
you should still see Choose first.

For 1.1, after to databind the items in the listbox in code you then
just add a new listitem to the dropdown in code as well.

Feb 14 '06 #4
Reconfigure your datasource parameters. You should be able to set a
default value for the parameter field in which you are telling it to
get its value from a control on the page, which is the dropdown. So, a
default value would be a valid dropdownlist value.

This is all I can think of from the top of my head.

Feb 14 '06 #5
Another way to add a default option to a dynamicly filled drop down is
to use;

mydropdown.Items.Insert(0,New ListItem("Choose...","none"))

add that after you bind it to the data source.

I ran into this issue earlier today and this worked for me. And similar
to 'GS' I was then stuck with another drop down that was auto populated
from the selection of the first drop down. But now that the
..SelectedValue was "none" it obviously didn't work. So what I created
was prior to the 1st drop down being selected the 2nd dropdown.Enabled
= False

Then I have a onchange event on the 1st DD that enables the 2nd DD and
runs the script to populate it on the postback based on the
..SelectedValue of the 1st DD.

Works like a charm. Hope that made sense.

Jeremy Reid
http://blackstaronline.net

Feb 15 '06 #6

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

Similar topics

6
by: chris yoker via DotNetMonster.com | last post by:
hiya, i have an xml doc, and I'd like to assign lookup values. Eg, if the "PRODUCT-TYPE" is 6, then I insert "bike" into the innerText. <code> <rows> <row> <PRODUCT-TYPE>6</PRODUCT-TYPE>...
1
by: chris yoker via DotNetMonster.com | last post by:
hiya, I'm still stuck at this one ;-( I want to overwrite the "numeric" value of my node with a lookup value. <xslt> <xsl:for-each select="PRODUCT-TYPE"> <xsl:choose> <xsl:when...
0
by: guido_brasletti | last post by:
Hi, I'm asking for help because I read dozens of threads on this subject, but I still cannot make it work. I'm developing an ASP script (running on a SBS 2k. I'm a beginner with ASP) to use on...
2
by: Max2006 | last post by:
Hi, I have a DropDown bound to a DataTable and I would like to add "Please Choose" as the 1st default item. I know that I can add "Please Choose" to the DataTable; but I wonder if I do the same...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.