473,394 Members | 1,718 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Dropdownlist setting index to 0

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
Nov 19 '05 #1
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
Nov 19 '05 #2

"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

Nov 19 '05 #3

"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

Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
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 ...
4
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...
6
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...
6
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...
3
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...
10
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 =...
1
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>...
1
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...
1
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...
0
by: MaryamSh | last post by:
Create Dynamic Dropdownlist Controls and related event -------------------------------------------------------------------------------- Hi, I am creating a Dynamic Search in my application. I...
0
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...
0
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...
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...
0
jinu1996
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...
0
tracyyun
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.