DropDownList

  • Thread starter Thread starter Mike D
  • Start date Start date
M

Mike D

I've databound the dropdownlist. How do I prevent it from selecting the
first item in the list during page load.
 
Mike said:
I've databound the dropdownlist. How do I prevent it from selecting the
first item in the list during page load.
Can you manually set the SelectedIndex to -1?
It would work

Andrey
 
Mike,

An item is always selected in the dropdownlist control. You cannot deselect
every item in the list at the same time. You can change the selection of the
list though by specifing an index to select (e.g. DropDownList1.SelectedIndex
= 3;). If i have misunderstood your question please reply to this post.

I hope this helps.
 
If I did a Sql select, for example the alpabet, the first letter "A" is
displayed in the dropdownlist yet I haven't clicked on the dropdown to
select a letter yet. If the dropdown is null, then I could search the whole
alphabet. I want the dropdownlist to display nothing until I click the
dropdown and select a value.
 
Mike,

I am not sure if I follow what you are saying. If there are no entries in
the dropdownlist the SelectedIndex will be equal to -1. So are you saying
that when the dropdownlist is in this state (SelectedIndex = -1 [no items in
the list]) and you click on the dropdownlist you want it to bind to the data
at that moment so you can make a selection?

If this is or is not correct please reply so I may understand more clearly
and try to help you.

Thanks.
 
Mike said:
If I did a Sql select, for example the alpabet, the first letter "A" is
displayed in the dropdownlist yet I haven't clicked on the dropdown to
select a letter yet. If the dropdown is null, then I could search the whole
alphabet. I want the dropdownlist to display nothing until I click the
dropdown and select a value.
Then you need to somehow add a blank as the first row in the binding dataset,
e.g if you use a query/view for dropdown box's data source, you can do like

select '' as your_column_name
UNION ALL SELECT whatever_you _select

This way you get a blank selected as the first row in the dadaset

Andrey
 
It's like Muzzy just suggested. I tried Muzzy's idea with the blank being
first and that will work. I'm used to Powerbuilder retrieving the
information but putting a null value in the dropdown until I click the
dropdown button and allowing me to select my options.

Thanks guys for all your help
 
Mike said:
It's like Muzzy just suggested. I tried Muzzy's idea with the blank being
first and that will work. I'm used to Powerbuilder retrieving the
information but putting a null value in the dropdown until I click the
dropdown button and allowing me to select my options.

Thanks guys for all your help

Any time ;)
Mike,

I am not sure if I follow what you are saying. If there are no entries in
the dropdownlist the SelectedIndex will be equal to -1. So are you saying
that when the dropdownlist is in this state (SelectedIndex = -1 [no items
in
the list]) and you click on the dropdownlist you want it to bind to the
data
at that moment so you can make a selection?

If this is or is not correct please reply so I may understand more clearly
and try to help you.

Thanks.
 
Back
Top