DropDownList is always returning the value from index 0

  • Thread starter Nathan Sokalski
  • Start date
N

Nathan Sokalski

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.
 
S

S. Justin Gengo

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
 
J

Juan T. Llibre

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/
==========================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top