Asp:DropDown - get selected item

R

Ronny Mandal

Hi!

I have an .aspx with some controls that are created dynamically. The
items are populated into the box by setting the DataSource-property to
a list. In addition I specify the text and value with DataTextField
and DataValueField; this works as expected.

However, my problems arises when I want to read the selected value
(i.e. after a postback caused by a change in the DropDown), the
selected item is always the first item in the DropDown. I do call the
DataBind-method, I believe that this might cause this.

My idea is to parse the selected value for a pattern and perform
operations on background of what this contains.

Anyone who know how to accomplish this?

Regards,

Ronny Mandal
 
M

MDoyle

Are you repopulating the DropDown after the the postBack? You may be
having an issue where the drop down isn't populated yet when you are
reading the selected item.
 
R

Ronny Mandal

Are you repopulating the DropDown after the the postBack? You may be
having an issue where the drop down isn't populated yet when you are
reading the selected item.
Yes, I am populating after the post-back. But if the the drop down
isn't populated,
how come that I always get the first item when I get the current
selected?

Regards,

Ronny Mandal
 
D

David Wier

You will always get the first item, if you don't enclose the population of
the DDL inside an if/then/postback block
if not page.ispostback then
- - populate ddl
end if

David Wier
http://aspnet101.com
http://iWritePro.com - One click PDF, convert .doc/.rtf/.txt to HTML with no
bloated markup
 
B

bruce barker

this method requires Viewstate to be turned on (bad idea). just recreate
the dropdown in OnInit, then the databind will be before the postback
data load event.

-- bruce (sqlwork.com)
 

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,582
Members
45,058
Latest member
QQXCharlot

Latest Threads

Top