Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Asp:DropDown - get selected item

0 views
Skip to first unread message

Ronny Mandal

unread,
Oct 11, 2007, 12:25:57 PM10/11/07
to
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

MDoyle

unread,
Oct 11, 2007, 12:29:32 PM10/11/07
to
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.

Ronny Mandal

unread,
Oct 11, 2007, 12:38:24 PM10/11/07
to
On Oct 11, 6:29 pm, MDoyle <MatthewRDo...@gmail.com> wrote:
> 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


David Wier

unread,
Oct 11, 2007, 12:46:40 PM10/11/07
to
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


"Ronny Mandal" <ron...@math.uio.no> wrote in message
news:1192120704.8...@57g2000hsv.googlegroups.com...

bruce barker

unread,
Oct 11, 2007, 1:50:25 PM10/11/07
to
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)

0 new messages