c# - DropDown 不触发 OnSelectedIndexChanged

标签 c# asp.net

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

   <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

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

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

关于c# - DropDown 不触发 OnSelectedIndexChanged,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16324413/

相关文章:

c# - 在 C# 中将字符串转换为 2 个小数位的最有效方法

c# - 在 Excel 和记事本中打开时将数字格式设置为 CSV 文本

c# - 如何获取 Zendesk 中的所有用户

c# - ASP.NET 无法引用类

c# - 货币的正则表达式缺少个位数?

c# - MVC : Ace editor post

asp.net - 响应.重定向

javascript - ASP :RadioButton and javascript function $find()

c# - HTML 到格式化文本 C#

asp.net - 当 IIS 已经处理请求并发时,为什么要使用异步 Controller ?