467,145 Members | 1,017 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,145 developers. It's quick & easy.

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
  • viewed: 1389
Share:
5 Replies
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by chris yoker via DotNetMonster.com | last post: by
1 post views Thread by chris yoker via DotNetMonster.com | last post: by
reply views Thread by guido_brasletti | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.