selectindexchanged上的asp.net列表框不会触发事件

问题描述:

<asp:ListBox ID="list1" runat="server" Height="200" Style=" margin: 0"   OnSelectedIndexChanged="list1_SelectedIndexChanged">
            <asp:ListItem Selected="True" Value="1">1</asp:ListItem>
            <asp:ListItem Value="2">2</asp:ListItem>
            <asp:ListItem Value="3">3</asp:ListItem>
            <asp:ListItem Value="4">4</asp:ListItem>
        </asp:ListBox>

我在updatePanel中有一个列表框

i have listbox in the updatePanel

但是当我选择某些东西时,它不会触发事件是怎么了?

but when i select something it doesn't fire an event what am doing wrong?

您需要将 AutoPostBack 属性设置为True.那么只有回发发生,并且您选择的索引事件将触发.

You need to Set AutoPostBack Property to True. then only Postback happens and your selected index event will fire.

<asp:ListBox AutoPostBack="true" ID="yourLIst" runat="server" Height="200" Style=" margin: 0"   OnSelectedIndexChanged="yourLIst_SelectedIndexChanged">