Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > DropDownList is always returning the value from index 0

Reply
Thread Tools

DropDownList is always returning the value from index 0

 
 
Nathan Sokalski
Guest
Posts: n/a
 
      09-04-2005
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
http://www.velocityreviews.com/forums/(E-Mail Removed)
http://www.nathansokalski.com/


 
Reply With Quote
 
 
 
 
S. Justin Gengo
Guest
Posts: n/a
 
      09-04-2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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
> (E-Mail Removed)
> http://www.nathansokalski.com/
>



 
Reply With Quote
 
 
 
 
Juan T. Llibre
Guest
Posts: n/a
 
      09-04-2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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
> (E-Mail Removed)
> http://www.nathansokalski.com/
>




 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
sorting index-15, index-9, index-110 "the human way"? Tomasz Chmielewski Perl Misc 4 03-04-2008 05:01 PM
DropDownList always returns value at index 0 Nathan Sokalski ASP .Net 4 09-18-2005 07:20 AM
DropDownList always returns value at index 0 Nathan Sokalski ASP .Net Web Controls 3 09-18-2005 06:45 AM
DropDownList is always returning the value from index 0 Nathan Sokalski ASP .Net Web Controls 2 09-04-2005 11:28 PM
DropDownList is always returning the value from index 0 Nathan Sokalski ASP .Net Building Controls 2 09-04-2005 11:28 PM



Advertisments