Marius Krämer
Marius Krämer

Reputation: 446

asp.net using c# DropDownList item not selected

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?

Upvotes: 1

Views: 1465

Answers (2)

Daryl
Daryl

Reputation: 18895

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.

Upvotes: 4

ashkufaraz
ashkufaraz

Reputation: 5297

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

        }

Upvotes: 1

Related Questions