473,396 Members | 1,987 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,396 software developers and data experts.

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********@hotmail.com
http://www.nathansokalski.com/
Nov 21 '05 #1
2 5911
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********@hotmail.com> wrote in message
news:ug**************@TK2MSFTNGP12.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********@hotmail.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.SelectedItem.Text

- To access the value
strVar = DropDownList1.SelectedItem.Value

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

"Nathan Sokalski" <nj********@hotmail.com> wrote in message
news:ug**************@TK2MSFTNGP12.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********@hotmail.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
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...
7
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...
3
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...
0
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
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,...
2
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...
0
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...
0
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...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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,...
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
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...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.