【问题标题】:DropDown not firing OnSelectedIndexChangedDropDown 不触发 OnSelectedIndexChanged
【发布时间】:2013-05-01 18:50:38
【问题描述】:

我有一个带有下拉列表的页面

   <asp:Content runat="server" ContentPlaceHolderID="ContentPlaceHolder1">
  <asp:DropDownList ID="DropDownList1" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
    <asp:ListItem>Cellsite</asp:ListItem>
    <asp:ListItem>Agreement</asp:ListItem>
    <asp:ListItem>Event</asp:ListItem>
    <asp:ListItem>User</asp:ListItem>
</asp:DropDownList>
<asp:Label runat="server" ID="EntityName"></asp:Label>
<ig:WebScriptManager ID="WebScriptManager1" runat="server"></ig:WebScriptManager>
<ig:WebDataGrid ID="EntityGrid" runat="server"  Width="100%">
    <Behaviors>
        <ig:Sorting>
        </ig:Sorting>
    </Behaviors>
</ig:WebDataGrid>

后面的代码是

     protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        EntityName.Text = DropDownList1.SelectedItem.Text;
    }

由于某种原因,标签永远不会更新,事件 selectedindexchanged 根本没有触发,我需要在此事件中添加动态网格。有什么线索吗?

【问题讨论】:

  • 设置下拉属性 autopostback = "true"

标签: c# asp.net


【解决方案1】:

您需要在下拉菜单中添加 AutoPostBack

 <asp:DropDownList ID="DropDownList1" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" AutoPostBack="true">

当您没有 AutoPostBack=true 属性时,您实际上可以判断没有回发。

【讨论】:

    【解决方案2】:

    设置下拉列表属性 AutoPostBack="true"

        <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
        <asp:ListItem>Cellsite</asp:ListItem>
        <asp:ListItem>Agreement</asp:ListItem>
         <asp:ListItem>Event</asp:ListItem>
         <asp:ListItem>User</asp:ListItem>
         </asp:DropDownList>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-05
      • 2014-02-20
      • 2013-09-13
      • 1970-01-01
      • 2016-05-24
      • 1970-01-01
      • 2013-02-03
      • 2012-02-28
      相关资源
      最近更新 更多