Question: Dropdownlist SelectedItem always returns 1st value!

V

VB Programmer

I have a dropdownlist which I populated on page_load. This works fine. I
simply do a ddlMyDdl.Items.Add(xxx)

I also have a button which references the CURRENTLY selected item in the ddl
like this:
ddlMyDdl.SelectedItem

The problem is that I am ALWAYS getting the first item back! Even when I
select the 5th item, the 10th item, etc....

Any ideas?

Thanks.
 
M

Marina

Does each of your items have a different value? Not just text, but the value
as well?
 
V

VB Programmer

I got it. I was clearing the ddl before I populated it in the page_load. I
had to put in a "If not page is postback" statement. Thanks.
 
S

Sam Fields

Do you have your .DataBind() for the ddl encapsulated in a "if
(!Page.IsPostBack)" expression? If you don't watch for postbacks, it will
re-build the items collection on the dll every time you post back and
therefore only return the currently selected item in the new collection,
namely the first item by default.

Hope this helps.
Sam
 
V

VB Programmer

THANKS EVERYONE!!!!

Sam Fields said:
Do you have your .DataBind() for the ddl encapsulated in a "if
(!Page.IsPostBack)" expression? If you don't watch for postbacks, it will
re-build the items collection on the dll every time you post back and
therefore only return the currently selected item in the new collection,
namely the first item by default.

Hope this helps.
Sam
 
Joined
Mar 11, 2008
Messages
1
Reaction score
0
Thankx very much!

Sam Fields :veryprou:
encapsulating bind event in Page.IsPostBack solved my problem.
 

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

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top