[英]asp.net using c# DropDownList item not selected
ASP.NET
using C#
: 使用C#
ASP.NET
:
I've got a DropdownList
and a Button
. 我有一个DropdownList
和一个Button
。
In Page_Load
I fill the DropdownList
manually via SQL-Query
with some items from the database. 在Page_Load
我通过SQL-Query
用数据库中的某些项手动填充DropdownList
。
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. 单击按钮后,我想Alert
列表中的所选项目,但是每次第一个项目提醒而不是所选项目。
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. 当单击按钮时发生回发并运行page_load并重新填充下拉列表,然后显示所选的第一项。
if (!IsPostBack)
{
//fill the dropdownlist
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.