[英]DropDownList: SelectedIndexChanged do not fire
I fill a ASP Dropdownlist in the pageload 我在页面加载中填写了一个ASP Dropdownlist
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
for (int i = 0; i < _maxStationsAnz; i++)
{
String stations = arrayList[1];
_allData = stations.Split(Convert.ToChar("/"));
_data = _allData[i].Split(Convert.ToChar(";"));
ddWeatherstations.Items.Add(_data[0]);
}
}
When a new station is selected, it should update informations. 选择新电台后,它应更新信息。 I use the
OnSelectedIndexChanged
attribute on my aspx site. 我在aspx网站上使用
OnSelectedIndexChanged
属性。
My code behind: 我后面的代码:
protected void ddWeatherstations_SelectedIndexChanged(object sender, EventArgs e)
{
for (int i = 0; i < _maxStationsAnz; i++)
{
if (ddWeatherstations.SelectedIndex == i)
{
lselected.Text = "Index changed!";
//unimportant code
//....
}
}
}
When I set a breakpoint and run the program and change the value of the dropdownlist, nothing happens. 当我设置一个断点并运行程序并更改下拉列表的值时,什么也没有发生。
You need to set AutoPostBack
property of your dropdownlist ddWeatherstations
to True
. 您需要将下拉列表
ddWeatherstations
AutoPostBack
属性设置为True
。
Try This: 尝试这个:
<asp:DropDownList ID="ddWeatherstations" runat="server" AutoPostBack="true"
OnSelectedIndexChanged="ddWeatherstations_SelectedIndexChanged">
</asp:DropDownList>
您需要设置属性AutoPostBack="true"
但是每次您选择DropDownList的其他索引时,这都会回发所有页面,因此我建议您将DropDownList放入AJAX更新面板中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.