1

ASP.NET using C#:

I've got a DropdownList and a Button.

In Page_Load I fill the DropdownList manually via SQL-Query with some items from the database.

After click on the button I want to Alert the selected item of the list but every time the first item alerts instead of the selected item.

So simple, but what am I doing wrong?

1
  • set code to if(!ispostback){code...} in page load Commented Nov 6, 2011 at 20:57

2 Answers 2

4

Without your code it's hard to say, but I'm guessing on your page load, your reloading your dropdownlist, which is removing the selected item, and giving you the first item every time.

If this is the case, check for the request being a postback, and don't repopulate the drop down list.

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

Comments

1

when click on button happen postback and run page_load and fill dropdown list agin then show first item that selected.

      if (!IsPostBack)
        { 

        //fill the dropdownlist

        }

Comments

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.