Is there a way to stop the system from setting the SelectedIndex of a
dropdownlist to 0?
I have it set at -1 in my code and if I push a button (that does nothing in
my test), during PostBack it will be set to 0.
I know that when I initially bind it from a table, it will set the
SelectedIndex to 0. I then have to procedurally set it to a -1. But then
if I push a button that does nothing, it will reset it list to 0, if it
isn't set to something else. If it were set to a 2 or a 3 it will still
show it set to a 2 or 3. If it is set to nothing (-1), it will set it to 0.
Is there a way to stop this behavior?
Thanks,
Tom 3 1832
On Tue, 19 Apr 2005 12:53:19 -0500, tshad <ts**********@ftsolutions.com>
wrote: Is there a way to stop the system from setting the SelectedIndex of a dropdownlist to 0?
I have it set at -1 in my code and if I push a button (that does nothing in my test), during PostBack it will be set to 0.
I know that when I initially bind it from a table, it will set the SelectedIndex to 0. I then have to procedurally set it to a -1. But then if I push a button that does nothing, it will reset it list to 0, if it isn't set to something else. If it were set to a 2 or a 3 it will still show it set to a 2 or 3. If it is set to nothing (-1), it will set it to 0.
Is there a way to stop this behavior?
Thanks,
Tom
No, because in HTML a dropdown (SELECT) automatically selects its first
item if no item was selected by default. One workaround is to add a
default or empty item at the top of the list and check against that being
selected (meaning nothing selected).
--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
"Craig Deelsnyder" <cdeelsny@no_spam_4_meyahoo.com> wrote in message
news:op***************@wtsp01tec520.nac.hscorp.com ... On Tue, 19 Apr 2005 12:53:19 -0500, tshad <ts**********@ftsolutions.com> wrote:
Is there a way to stop the system from setting the SelectedIndex of a dropdownlist to 0?
I have it set at -1 in my code and if I push a button (that does nothing in my test), during PostBack it will be set to 0.
I know that when I initially bind it from a table, it will set the SelectedIndex to 0. I then have to procedurally set it to a -1. But then if I push a button that does nothing, it will reset it list to 0, if it isn't set to something else. If it were set to a 2 or a 3 it will still show it set to a 2 or 3. If it is set to nothing (-1), it will set it to 0.
Is there a way to stop this behavior?
Thanks,
Tom
No, because in HTML a dropdown (SELECT) automatically selects its first item if no item was selected by default. One workaround is to add a default or empty item at the top of the list and check against that being selected (meaning nothing selected).
But if you set the SelectionMode to Multiple, you don't have this problem.
When I look at view source, I see an attribute "multiple" there.
Is there an attribute that says 0 or 1?
Thanks,
Tom -- Craig Deelsnyder Microsoft MVP - ASP/ASP.NET
"Craig Deelsnyder" <cdeelsny@no_spam_4_meyahoo.com> wrote in message
news:op***************@wtsp01tec520.nac.hscorp.com ... On Tue, 19 Apr 2005 12:53:19 -0500, tshad <ts**********@ftsolutions.com> wrote:
Is there a way to stop the system from setting the SelectedIndex of a dropdownlist to 0?
I have it set at -1 in my code and if I push a button (that does nothing in my test), during PostBack it will be set to 0.
I know that when I initially bind it from a table, it will set the SelectedIndex to 0. I then have to procedurally set it to a -1. But then if I push a button that does nothing, it will reset it list to 0, if it isn't set to something else. If it were set to a 2 or a 3 it will still show it set to a 2 or 3. If it is set to nothing (-1), it will set it to 0.
Is there a way to stop this behavior?
Thanks,
Tom
No, because in HTML a dropdown (SELECT) automatically selects its first item if no item was selected by default. One workaround is to add a default or empty item at the top of the list and check against that being selected (meaning nothing selected).
Also, if I set it to a -1, the html shows nothing being selected. But the
next time I post back, it does.
I assume that it is asp.net that is building the HTML to set the index. But
for some reason it has decided to set the first item as selected in some
instances.
Tom -- Craig Deelsnyder Microsoft MVP - ASP/ASP.NET This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: TOm |
last post by:
How do I bind a SqlDataReader to a dropdownlist box?
I know how to construct a SqlDataReader dr and get the
values. Buit how do I bind it to a DropDownList box in C#?
This does not work
...
|
by: DotNetJunky |
last post by:
I have built a control that runs an on-line help system. Depending on the
category you selected via dropdownlist, it goes out and gets the child
subcategories, and if there are any, adds a new...
|
by: Robin Bonin |
last post by:
In my user contol I am creating a set of dropdownlists.
Each list is created based on input from the other lists.
The problem I am having is setting the selected index on
the lists.
If someone...
|
by: tfs |
last post by:
I have a dropdownlist that I was setting to an index (which happened
to be the same as the value). I changed this to a character as that
is what I want to have in my database.
<asp:dropdownlist...
|
by: Tim::.. |
last post by:
Can someone please tell me how I go about preselecting an item in a drop
drown list when I click the Edit Command in a datagrid?
I have tried the following but it doesn't work for me!
I would...
|
by: dhnriverside |
last post by:
Hi guys
Still having a problem with this dropdownlist.
Basically, I've got 4. The first 2 work fine, then my code crashes on the
3rd.
ddlEndTimeHour.Items.FindByValue(endTime).Selected =...
|
by: clickon |
last post by:
Forget about the controlParameter for the moment, for testing purposes i have
created the following
Markup:
<asp:Table ID="tblSelectRoute" runat="server" CssClass="asp-table">
<asp:TableRow>...
|
by: Jason Wilson |
last post by:
I have two dropdownlists that are bound to the same datasource and I
have a couple of questions:
1) Because they are bound to the same datasource, I am assuming that
they only make 1 round trip...
|
by: MaryamSh |
last post by:
Hi,
I am creating a Dynamic Search in my application.
I create a user control and in Page_load event I create a dynamic dropdownlist and 2 dynamic button (Add,Remove)
By pressing Add button...
|
by: MaryamSh |
last post by:
Create Dynamic Dropdownlist Controls and related event
--------------------------------------------------------------------------------
Hi,
I am creating a Dynamic Search in my application.
I...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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: 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...
| |