我的代码:
*.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);
}但这不管用。
发布于 2011-04-26 16:42:35
尝试在此下拉列表中设置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);
}发布于 2011-04-26 16:44:22
我想你错过了aspx文件中的AutoPostBack="true“属性。
发布于 2011-04-26 16:46:14
在你的aspx代码中添加AutoPostBack="true“,一切都会如你所想的那样工作。
https://stackoverflow.com/questions/5787922
复制相似问题