Question: Dropdownlist SelectedItem always returns 1st value!

  • Thread starter Thread starter VB Programmer
  • Start date Start date
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.
 
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.
 
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
 
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
 

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

Back
Top