SelectedIndexChanged不起作用!

时间:2011-04-26 08:42:04

标签: c# events sharepoint-2010 selectedindexchanged

我的代码:

* 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);
}

但这不起作用。

3 个答案:

答案 0 :(得分:13)

尝试在此下拉列表中设置AutoPostBack="true"

<asp:DropDownList 
    ID="CountryList" 
    CssClass="CountryList" 
    runat="server" 
    OnSelectedIndexChanged="CountryList_SelectedIndexChanged"
    AutoPostBack="true"  
/>

此外,您无需在Page_Load方法中手动连接事件处理程序。它将在编译webform时由ASP.NET自动完成:

protected void Page_Load(object sender, EventArgs e)
{
    ... 
}

protected void CountryList_SelectedIndexChanged(object sender, EventArgs e)
{
    LoadCityList(CountryList, CityList);
}

答案 1 :(得分:1)

我认为您错过了aspx文件中的AutoPostBack =“true”属性

答案 2 :(得分:1)

在你的aspx代码中添加AutoPostBack =“true”,一切都会按照你的想法运作。