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?
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.
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
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.