Go Back   Velocity Reviews > Newsgroups > ASP Net
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

ASP Net - How do you set DataBound Dropdownlist to "Choose"?

 
Thread Tools Search this Thread
Old 02-14-2006, 09:07 PM   #1
Default How do you set DataBound Dropdownlist to "Choose"?


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
  Reply With Quote
Old 02-14-2006, 09:20 PM   #2
tdavisjr
 
Posts: n/a
Default Re: How do you set DataBound Dropdownlist to "Choose"?
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
  Reply With Quote
Old 02-14-2006, 09:23 PM   #3
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
 
Posts: n/a
Default RE: How do you set DataBound Dropdownlist to "Choose"?
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=?=
  Reply With Quote
Old 02-14-2006, 10:13 PM   #4
GS
 
Posts: n/a
Default Re: How do you set DataBound Dropdownlist to "Choose"?
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
  Reply With Quote
Old 02-14-2006, 10:36 PM   #5
tdavisjr
 
Posts: n/a
Default Re: How do you set DataBound Dropdownlist to "Choose"?
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
  Reply With Quote
Old 02-15-2006, 12:04 AM   #6
blackstaronline.net
 
Posts: n/a
Default Re: How do you set DataBound Dropdownlist to "Choose"?
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
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

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




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46