【问题标题】:Why isn't selectedindexchanged firing?为什么 selectedindexchanged 不触发?
【发布时间】:2011-10-12 17:26:25
【问题描述】:

我定义了以下 DropDownList:

<asp:DropDownList ID="ddlStuff" CssClass="myCssClass" OnSelectedIndexChanged="PopulateAnotherDropdown" runat="server"></asp:DropDownList>

但是,我的 PopulateAnotherDropdown 方法没有触发。我在该方法上设置了一个断点,但它没有被命中。

这是我在代码隐藏中编写的方法:

public void PopulateAnotherDropdown(object sender, EventArgs e)
{
    ...
}

对于它的价值,页面呈现如下:

<select name="ctl00$MainContent$ddlStuff" id="MainContent_ddlStuff" class="myCssClass">

有什么想法吗?

【问题讨论】:

    标签: c# .net asp.net drop-down-menu code-behind


    【解决方案1】:

    因为你忘了加:AutoPostBack="true"

    要触发下拉列表控件的 SelectedIndex,它需要回发到服务器。为此,您必须在控件属性中设置 AutoPostBack="true"

    【讨论】:

      【解决方案2】:

      请设置

      AutoPostBack="true"
      

      的下拉菜单。因为默认情况下除了按钮控件之外它是false

      【讨论】:

        猜你喜欢
        • 2011-01-28
        • 2012-01-11
        • 1970-01-01
        • 2010-10-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-07-29
        • 1970-01-01
        相关资源
        最近更新 更多