Asp:DropDown - get selected item

  • Thread starter Thread starter Ronny Mandal
  • Start date Start date
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
 
Ronny Mandal said:
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.

This typically hapens if you do the databinding in Page_load without
enclosing the code in an "if (!IsPostBack)". Since the Page_Load always
executes during every postback before the SelectedIndexChanged event, the
dropdown loses the selecteditem (because it is databound again) before you
can read it in the SelectedIndexChanged event.
 
Back
Top