2012-06-14 40 views
0

我有一個帶有dropdownbox兩個列表框和兩個按鈕的窗體。Listbox.SelectedIndex不會改變,在一些asp屬性更改後,出了什麼問題?

我刪除了「選擇」按鈕,我只是用DropDownList1_SelectedIndexChanged,但該事件不會觸發,直到我從使用的建議: Why DropDownList.SelectedIndexChanged event does not fire?

它涉及改變AutoPostBack='true'EnableViewState="true"性能

因此,現在DropDownList可以工作,但使用兩個列表框,SelectedIndex保持爲-1,即使選中也不會改變。

列表框代碼:

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

的DropDownList代碼:

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

按鈕的Click事件代碼:

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現在總是說,沒有用戶已經選擇,但有一個用戶選擇,非常奇怪。

任何想法?我認爲它與postbox,page_load或列表框的selectedindex changed事件有關,它在我進行修改之前完美運行。

回答

1

問題在於回發,並且填充列表框的代碼位於dropbox_load子例程中。這意味着列表框每次在頁面上發生變化時都會重新填充,因此selecteditem索引將恢復爲-1。

相關問題