473,773 Members | 2,277 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DropDownList is always returning the value from index 0

I have a DropDownList that is returning the value from index 0 regardless of
which item is selected. The code that I am using to test which index it is
returning is:

Label1.Text = ddlDeleteEvents .SelectedIndex
This is the first line of code in a Button's Click event handler, so I know
that there is no other code changing the selected value before I use it.
What is happening here? Any help would be appreciated. Thanks.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/
Nov 21 '05 #1
2 5939
Nathan,

This is only a guess, but a very common oversight is binding the drop down
list on every page load which resets the selected item.

In your code, where you bind your drop down list, put:

If Not Page.IsPostBack Then
'---Bind your drop down here
End If

That should take care of it if my guess is correct.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Nathan Sokalski" <nj********@hot mail.com> wrote in message
news:ug******** ******@TK2MSFTN GP12.phx.gbl...
I have a DropDownList that is returning the value from index 0 regardless
of which item is selected. The code that I am using to test which index it
is returning is:

Label1.Text = ddlDeleteEvents .SelectedIndex
This is the first line of code in a Button's Click event handler, so I
know that there is no other code changing the selected value before I use
it. What is happening here? Any help would be appreciated. Thanks.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/

Nov 21 '05 #2
You can access the text and value properties
of the selected item in code like this :

Dim strVar as String

- To access the text

strVar = DropDownList1.S electedItem.Tex t

- To access the value
strVar = DropDownList1.S electedItem.Val ue

Juan T. Llibre
ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
=============== ===========

"Nathan Sokalski" <nj********@hot mail.com> wrote in message
news:ug******** ******@TK2MSFTN GP12.phx.gbl...
I have a DropDownList that is returning the value from index 0 regardless of which item
is selected. The code that I am using to test which index it is returning is:

Label1.Text = ddlDeleteEvents .SelectedIndex
This is the first line of code in a Button's Click event handler, so I know that there
is no other code changing the selected value before I use it. What is happening here?
Any help would be appreciated. Thanks.
--
Nathan Sokalski
nj********@hotm ail.com
http://www.nathansokalski.com/


Nov 21 '05 #3

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

Similar topics

0
1207
by: John | last post by:
Hi, I have a dropdownlist with x amount of list items, however quite often a lot of the list items have the same value. The dropdownlist is bound to an ArrayList of objects and I'm using the selectedindex (-1) to access the corresponding object of the item selected from the list. However, for instance, if there is 5 items with the same value, and I select
7
2041
by: Lastie | last post by:
Hi all, I’ve got a ‘dropdownlist’ web control and I can add ‘listitem’ no problem. I can also bind data from an SQL database fine. My problem is that I want to do both at the same time to allow me to have the first option in the list a ‘listitem’ saying something like ‘please pick an option’, and then the rest of options coming from the database. <asp:dropdownlist id="fm_Category" runat="server"...
3
2930
by: Olivier Verdin | last post by:
Hi, I have a page with several Textboxes and several DropDownList. When I click on a 'save' button, it creates a record in a database. The page works fine under Internet Explorer. It does not work under FireFox. The dropdownlist are always selecting the zero index value. If I debug and I stop the program in the page_load, the dropdownlist are already set to zero index.
0
1029
by: Gunjan Garg | last post by:
The issue here is - When the postback event happens the selected index is always returing the first value. Appreciate your help in advance. Thanks Here is the code ----------------------------------------------------------------------------
4
2011
by: Mark Waser | last post by:
I've discovered a very odd bug when attempting to put a dropdown list in a datagrid. In the page PreRender step, the selected index of the datagrid is successfully set during databinding. Yet, when the datagrid enters it's own OnPreRender, the selected index has reverted to zero. I created a debug version of the dropdown list which inherited from dropdownlist and overrode the selected index property to trace.write whenever it was...
2
8200
by: keniget | last post by:
Hope I'm posting this in the right place. Has anyone encountered the need to have more than one datavaluefield? At present, I'm returning two columns, a StateID and a StateDesc and they are being put into the datavaluefield and datatextfield respectively. I could REALLY do with binding another column to the dropdownlist as I require additional information about these states...
0
1811
by: Moneypenny | last post by:
Hi there, I have a Gridview control which has a dropdownlist in every row. The dropdowns are populated dynamically from a database (so the content is different in each row. There is also a select button for each row so that the the user can choose a row and the values will be added to a shopping cart. My problem is that the page loads fine and everything is showing as it should be. However, when I select a row the dropdownlist for that row...
0
1274
by: MrVystery | last post by:
Hello I have a problem with a webapplication that is developed in ASP.NET 2.0 c#. Im having a window open with a type of "report" i have a dropdownlist that has status for the report. I can save the report with different types of statuses. It work fine but the problem is when i leave this "report" open, working with it ,taking a coffe-break and returning, working with the report again and finally im going to set it as "Approved" in...
1
4659
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 ,another row will be created with the same control (I mean another dropdown and 2 button) and so on. and by pressing Remove button the selecetd row will be removed. I used viewstate to keep my value for postback, I want by changing selectedvalue of...
0
9621
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10264
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10039
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9914
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7463
isladogs
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5355
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3610
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.