gpt4 book ai didi

c# - SelectedIndexChanged 不起作用!

转载 作者:行者123 更新时间:2023-11-30 13:17:51 24 4
gpt4 key购买 nike

我的代码:

*.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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com