How do you set DataBound Dropdownlist to "Choose"?

G

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

tdavisjr

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

Guest

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
 
G

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).
 
T

tdavisjr

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

blackstaronline.net

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top