DropDownList不会运行后面的代码

时间:2011-11-17 14:28:32

标签: asp.net

HY, 我配置了dropdownlist

<asp:DropDownList ID="ddl_filter1" runat="server" Width="120px" DataSourceID="ObjectDataSource1"
                                        DataTextField="PLC" DataValueField="PLC" OnSelectedIndexChanged="ddl_filter1_SelectedIndexChanged" />

我希望当我从DropDownList选择一个值时,会发生一个事件

但是对于某些原因,背后的代码不会运行。

我的代码中有什么问题?

2 个答案:

答案 0 :(得分:1)

您是否将AutoPostBack="true"用于ddl?

您的代码将是:

<asp:DropDownList ID="ddl_filter1" runat="server" Width="120px" DataSourceID="ObjectDataSource1"
      DataTextField="PLC" DataValueField="PLC" AutoPostBack="true" OnSelectedIndexChanged="ddl_filter1_SelectedIndexChanged" />

答案 1 :(得分:1)

您需要将Autopostback设置为true。

示例:

<asp:DropDownList   
             ID="DropDownList1"  
             runat="server"  
             AutoPostBack="true"  
             OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"  
             >  
             <asp:ListItem>HyperLink</asp:ListItem>  
             <asp:ListItem>PasswordRecovery</asp:ListItem>  
             <asp:ListItem>PlaceHolder</asp:ListItem>  
             <asp:ListItem>LoginName</asp:ListItem>  
             <asp:ListItem>Label</asp:ListItem>  
        </asp:DropDownList>