When I load a drop down list from a dataset, it defaults to selecting the
first item. How do I get it to not select anything and leave the ddl blank
until a user selects an item? I tried:
ddl.SelectedIndex = -1
but it still selects the first item, returning the selected index of 0
Thanks for your help. 8 1234
After you populate the drop down add this code:
ddl.items.insert(0," ")
"eagle" <ea***@yahoo.com> wrote in message
news:eq**************@TK2MSFTNGP10.phx.gbl... When I load a drop down list from a dataset, it defaults to selecting the first item. How do I get it to not select anything and leave the ddl blank until a user selects an item? I tried:
ddl.SelectedIndex = -1 but it still selects the first item, returning the selected index of 0
Thanks for your help.
I don't think you can do that. You have to add a "--make a selection-"
option to your list of items.
An easy way to do that is to bind your dropdownlist, then add code like
this:
DropDownList.Datasource = foobar
DropDownList.DataBind
DropDownList1.Items.Insert(0, "-make a selection-")
You can put a requirefield validator on it to make sure they choose
something other than that first selection.
Greg
"eagle" <ea***@yahoo.com> wrote in message
news:eq**************@TK2MSFTNGP10.phx.gbl... When I load a drop down list from a dataset, it defaults to selecting the first item. How do I get it to not select anything and leave the ddl blank until a user selects an item? I tried:
ddl.SelectedIndex = -1 but it still selects the first item, returning the selected index of 0
Thanks for your help.
That true. Your first choice doesn't really have to have any text in it. :)
Greg
"Scott M." <s-***@nospam.nospam> wrote in message
news:Ow**************@TK2MSFTNGP12.phx.gbl... After you populate the drop down add this code:
ddl.items.insert(0," ") "eagle" <ea***@yahoo.com> wrote in message news:eq**************@TK2MSFTNGP10.phx.gbl... When I load a drop down list from a dataset, it defaults to selecting the first item. How do I get it to not select anything and leave the ddl blank until a user selects an item? I tried:
ddl.SelectedIndex = -1 but it still selects the first item, returning the selected index of 0
Thanks for your help.
If you are going to add a required field validator to ensure that any choice
but the first is chosen, you'd have to add the following, otherwise the
newly added first choice would be considered a valid selection:
DropDownList.Datasource = foobar
DropDownList.DataBind
DropDownList1.Items.Insert(0, "-make a selection-")
--------------------> dropdownlist.SelectedItem.Value = ""
<----------------------------------
I usually do it like so:
DropDownList1.Items.Insert(0, New ListItem("-make a selection-",""))
For some reason I was thinking DropDownList1.Items.Insert(0, "-make a
selection-") made the value="". But I guess it just defaults value to
whatever the text is instead.
Greg
"Scott M." <s-***@nospam.nospam> wrote in message
news:Oh*************@tk2msftngp13.phx.gbl... If you are going to add a required field validator to ensure that any choice but the first is chosen, you'd have to add the following, otherwise the newly added first choice would be considered a valid selection:
DropDownList.Datasource = foobar DropDownList.DataBind DropDownList1.Items.Insert(0, "-make a selection-") --------------------> dropdownlist.SelectedItem.Value = "" <----------------------------------
All list item values default to the text of the item, unless otherwise
specified. So, you need to null out the value of the first choice if you
don't want the required field validator to allow that choice.
As for creating a New ListItem during the Insert, it really isn't necessary
since Insert implicitly creates a new ListItem anyway. With your code, in
the end, you'd have 2 new list items created in memory, when you only wanted
one.
"Greg Burns" <bl*******@newsgroups.nospam> wrote in message
news:uH**************@TK2MSFTNGP15.phx.gbl... I usually do it like so:
DropDownList1.Items.Insert(0, New ListItem("-make a selection-",""))
For some reason I was thinking DropDownList1.Items.Insert(0, "-make a selection-") made the value="". But I guess it just defaults value to whatever the text is instead.
Greg
"Scott M." <s-***@nospam.nospam> wrote in message news:Oh*************@tk2msftngp13.phx.gbl... If you are going to add a required field validator to ensure that any choice but the first is chosen, you'd have to add the following, otherwise the newly added first choice would be considered a valid selection:
DropDownList.Datasource = foobar DropDownList.DataBind DropDownList1.Items.Insert(0, "-make a selection-") --------------------> dropdownlist.SelectedItem.Value = "" <----------------------------------
Are you sure? Insert only implicitly createa a new ListItem if you pass it
a string. I am passing it a ListItem as an argument using one of its
overloaded methods.
"Scott M." <s-***@nospam.nospam> wrote in message
news:OU**************@TK2MSFTNGP15.phx.gbl... All list item values default to the text of the item, unless otherwise specified. So, you need to null out the value of the first choice if you don't want the required field validator to allow that choice.
As for creating a New ListItem during the Insert, it really isn't necessary since Insert implicitly creates a new ListItem anyway. With your code, in the end, you'd have 2 new list items created in memory, when you only wanted one.
"Greg Burns" <bl*******@newsgroups.nospam> wrote in message news:uH**************@TK2MSFTNGP15.phx.gbl...I usually do it like so:
DropDownList1.Items.Insert(0, New ListItem("-make a selection-",""))
For some reason I was thinking DropDownList1.Items.Insert(0, "-make a selection-") made the value="". But I guess it just defaults value to whatever the text is instead.
Greg
"Scott M." <s-***@nospam.nospam> wrote in message news:Oh*************@tk2msftngp13.phx.gbl... If you are going to add a required field validator to ensure that any choice but the first is chosen, you'd have to add the following, otherwise the newly added first choice would be considered a valid selection:
DropDownList.Datasource = foobar DropDownList.DataBind DropDownList1.Items.Insert(0, "-make a selection-") --------------------> dropdownlist.SelectedItem.Value = "" <----------------------------------
Oh yes, sorry about that... you are right. Since you are passing a listitem
(using an overloaded Insert method), it would not create a second listitem.
I still prefer to pass just the string though (less code = less work).
:)
"Greg Burns" <bl*******@newsgroups.nospam> wrote in message
news:ud****************@tk2msftngp13.phx.gbl... Are you sure? Insert only implicitly createa a new ListItem if you pass it a string. I am passing it a ListItem as an argument using one of its overloaded methods.
"Scott M." <s-***@nospam.nospam> wrote in message news:OU**************@TK2MSFTNGP15.phx.gbl... All list item values default to the text of the item, unless otherwise specified. So, you need to null out the value of the first choice if you don't want the required field validator to allow that choice.
As for creating a New ListItem during the Insert, it really isn't necessary since Insert implicitly creates a new ListItem anyway. With your code, in the end, you'd have 2 new list items created in memory, when you only wanted one.
"Greg Burns" <bl*******@newsgroups.nospam> wrote in message news:uH**************@TK2MSFTNGP15.phx.gbl...I usually do it like so:
DropDownList1.Items.Insert(0, New ListItem("-make a selection-",""))
For some reason I was thinking DropDownList1.Items.Insert(0, "-make a selection-") made the value="". But I guess it just defaults value to whatever the text is instead.
Greg
"Scott M." <s-***@nospam.nospam> wrote in message news:Oh*************@tk2msftngp13.phx.gbl... If you are going to add a required field validator to ensure that any choice but the first is chosen, you'd have to add the following, otherwise the newly added first choice would be considered a valid selection:
DropDownList.Datasource = foobar DropDownList.DataBind DropDownList1.Items.Insert(0, "-make a selection-") --------------------> dropdownlist.SelectedItem.Value = "" <----------------------------------
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Marlene harkcom |
last post by:
I've got a datagrid with 5 bound columns in it as well as
an edit/update/cancel column. I'm binding this to a
dataset. One of the fields is always going to be one of
three values.
I want the...
|
by: Sam |
last post by:
Hi,
Do you know if it's possible to have a datagrid that contains drop-down
lists ?
Thx
|
by: accyboy1981 |
last post by:
Hi,
I new to C# so please forgive me if this is simple. I've got 2 drop
down lists the first is hard coded with data where as the second is
populated from a database. The options that appear in...
|
by: Ed Dror |
last post by:
Hi there
ASP.NET 2.0 VB & SQL Express
Lest take Northwind Categories Products as example
I create a table that hold these two together
and I create a stored procedure like
select ProductID,...
|
by: RAM |
last post by:
I need to have two drop down lists in a edited row of a data list. One drop
down list should contain Groups and the second one should contain Materials
from *selected* group.
Thus, I have written:...
|
by: Prof |
last post by:
Hi,
I have the requirement of autoupdating the drop down lists , when a
selectin is done in another drop down box. I dont have a server through
which i can make it dynamic. I have to hard code...
|
by: penny111 |
last post by:
Hi there,
For my application, i need to have 3 drop down lists
1. drop down list of folder names
2. drop down list of documents in the folder selected
3. drop down list of instances of the...
|
by: rodeoval |
last post by:
I need to have three drop down lists, but the dependent should get the values from the database without refreshing the page..If knows,someone pls reply soon
|
by: coolsti |
last post by:
I am not new to Javascript and have been working with it for years now. I have also written my own parent - child and parent - child - child drop down lists.
But when I look at some web sites, I...
|
by: George Best |
last post by:
Hi everyone,
I am trying to make three dynamic drop down lists. When I say dynamic I mean when I choose a value from the first one, the second one changes options and when I choose a value from...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |