1

On an aspx page I have a dropdownlist and a button.

I select a value from the dropdownlist and click the button.

In the button event handler I have the statment: DropDownList1.SelectedValue;

This value is showing up as the first item in the list regardless of what item is actually selected.

Same result with .SelectedItem.Value and .Text

Why? And how do I get the item actually selected?

3
  • 1
    Do you rebind your Dropdown on every postback to the Datasource? Or do you have the same value for every item? Commented Oct 27, 2010 at 12:13
  • ? whats the question here? its working as it should... Commented Oct 27, 2010 at 12:21
  • @user287745 - clearly i'm having an issue or I would not have posted. It may be working as it should, but I'm asking how to make it work like I want to. Give me the item selected not the first item in the list Commented Oct 27, 2010 at 12:34

1 Answer 1

2

Ok, i create an answer from my comment.

Do you rebind your Dropdown on every postback to the Datasource or do you have the same value for every item?

Always check for Page.IsPostback when you bind controls to a Datasource.

Sign up to request clarification or add additional context in comments.

3 Comments

the button is actually a remove button. So the list has say two items. I selected the second and click the remove button. The event handler is supposed to get the selected value and remove it and then rebind. However I can't do that because i'm getting the first item in the list not the selected one.
You didn't even have answered one of my two questions that could cause a wrong selected item. Btw, what is theSelectedIndex of the Dropdown? Please show us some code of your databinding and event handler.
Sorry. I was researching the other two answers. didn't want to speculate. I was binding in the pageload which is unnecessary because i do the bind both when the add button is clicked and when the remove button is clicked. I removed these binds from my page load altogether and it works. Thanks! your mention of the binding on postback lead me to the answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.