我的代码:
*.aspx:
<asp:DropDownList ID="CountryList" CssClass="CountryList" runat="server"
OnSelectedIndexChanged="CountryList_SelectedIndexChanged" />
*.aspx.cs:
protected void Page_Load(object sender, EventArgs e)
{
CountryList.SelectedIndexChanged +=
new EventHandler(CountryList_SelectedIndexChanged);
...
}
protected void CountryList_SelectedIndexChanged(object sender, EventArgs e)
{
LoadCityList(CountryList, CityList);
}
但这行不通。
最佳答案
尝试设置 AutoPostBack="true"
在此下拉列表中:
<asp:DropDownList
ID="CountryList"
CssClass="CountryList"
runat="server"
OnSelectedIndexChanged="CountryList_SelectedIndexChanged"
AutoPostBack="true"
/>
此外,您不需要在 Page_Load
方法中手动连接事件处理程序。它会在 ASP.NET 编译 webform 时自动完成:
protected void Page_Load(object sender, EventArgs e)
{
...
}
protected void CountryList_SelectedIndexChanged(object sender, EventArgs e)
{
LoadCityList(CountryList, CityList);
}
关于c# - SelectedIndexChanged 不起作用!,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5787922/