Listbox.SelectedIndex 没有更改,经过一些 asp 属性更改后,出了什么问题



我有一个表单,上面有一个下拉框两个列表框和两个按钮。

我删除了一个"选择"按钮,因为我刚刚使用了DropDownList1_SelectedIndexChanged,但在我使用以下建议之前,该事件不会触发:为什么 DropDownList.SelectedIndexChanged 事件不触发?

它涉及更改AutoPostBack='true'EnableViewState="true"属性

所以现在 DropDownList 可以工作了,但对于两个列表框,SelectedIndex 保持为 -1,即使被选中也不会更改。

列表框代码:

<asp:ListBox ID="ListBox1" runat="server" EnableViewState="true" 
    Height="207px" Width="168px"></asp:ListBox>

下拉列表代码:

<asp:DropDownList ID="DropDownList1" runat="server" EnableViewState="true"
    AutoPostBack="true" style="font-weight: 700; margin-left: 26px">

按钮单击事件代码:

If (ListBox1.SelectedIndex < 0) Then 'No user selected
    MsgBox("Please select a user to add from the Listbox on the left.", vbCritical, "ListBox2 Validation Error")
Else

MsgBox现在总是说没有用户被选中,但有一个用户选择,非常奇怪。

有什么想法吗?我认为这与回发、page_load或列表框的 selectedindex 更改事件有关,它在我进行修改之前运行良好。

问题是回发,填充列表框的代码位于dropbox_load子例程中。这意味着每次页面上发生更改时,列表框都会重新填充,因此 selecteditem 索引将恢复为 -1。

相关内容

最新更新