开发者

SelectedIndexChanged doesn't work!

开发者 https://www.devze.com 2023-03-01 05:10 出处:网络
My code: *.aspx: <asp:DropDownList ID开发者_C百科=\"CountryList\" CssClass=\"CountryList\" runat=\"server\"

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消