Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net Building Controls (http://www.velocityreviews.com/forums/f59-asp-net-building-controls.html)
-   -   DropDownList is always returning the value from index 0 (http://www.velocityreviews.com/forums/t757924-dropdownlist-is-always-returning-the-value-from-index-0-a.html)

Nathan Sokalski 09-04-2005 11:07 PM

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
njsokalski@hotmail.com
http://www.nathansokalski.com/



S. Justin Gengo 09-04-2005 11:16 PM

Re: DropDownList is always returning the value from index 0
 
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" <njsokalski@hotmail.com> wrote in message
news:ughznVasFHA.3216@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
> njsokalski@hotmail.com
> http://www.nathansokalski.com/
>




Juan T. Llibre 09-04-2005 11:28 PM

Re: DropDownList is always returning the value from index 0
 
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" <njsokalski@hotmail.com> wrote in message
news:ughznVasFHA.3216@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
> njsokalski@hotmail.com
> http://www.nathansokalski.com/
>






All times are GMT. The time now is 04:59 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.