DropDown没有触发OnSelectedIndexChanged

时间:2013-05-01 18:50:39

标签: 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;
    }

对于某些原因,标签永远不会更新,selectindexchanged的事件根本不会触发我需要在此事件中添加动态网格。任何线索?

2 个答案:

答案 0 :(得分:4)

您需要在下拉列表中添加AutoPostBack

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

当你没有AutoPostBack = true属性时,你实际上可以告诉你没有回发帖。

答案 1 :(得分:0)

设置dropdownlist属性AutoPostBack =&#34; true&#34;

    <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>