![]() |
|
|
|||||||
![]() |
ASP Net - How do you set DataBound Dropdownlist to "Choose"? |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
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? GS |
|
|
|
|
#2 |
|
Posts: n/a
|
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. tdavisjr |
|
|
|
#3 |
|
Posts: n/a
|
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? =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?= |
|
|
|
#4 |
|
Posts: n/a
|
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" <> wrote in message news: 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. > GS |
|
|
|
#5 |
|
Posts: n/a
|
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. tdavisjr |
|
|
|
#6 |
|
Posts: n/a
|
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 blackstaronline.net |
|
![]() |
| Thread Tools | Search this Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Custom control dropdownlist - need advice | tcstom | Software | 0 | 04-18-2008 11:28 AM |
| databound Drop Down List not changing on new selection | KROSS | General Help Related Topics | 0 | 01-21-2008 04:48 PM |
| dynamic validations for checkboxlist and dropdownlist | mrugesh_dulera | Software | 0 | 06-26-2007 01:56 AM |
| DropdownList in gridview | visj4u | Software | 0 | 04-27-2007 01:11 PM |
| DropDownList | neoupadhyay | Software | 0 | 03-23-2007 02:23 PM |