SelectedIndexChanged doesn't work!
My code:
*.aspx:
<asp:DropDownList ID开发者_C百科="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);
}
But this doesn't work.
Try setting AutoPostBack="true"
on this dropdown list:
<asp:DropDownList
ID="CountryList"
CssClass="CountryList"
runat="server"
OnSelectedIndexChanged="CountryList_SelectedIndexChanged"
AutoPostBack="true"
/>
Also you don't need to manually wire-up the event handler in the Page_Load
method. It will be automatically done by ASP.NET when it compiles the webform:
protected void Page_Load(object sender, EventArgs e)
{
...
}
protected void CountryList_SelectedIndexChanged(object sender, EventArgs e)
{
LoadCityList(CountryList, CityList);
}
I think you missed AutoPostBack="true" Property in aspx file
Add AutoPostBack="true" in ur aspx code and everything will work as you thought.
精彩评论