0

I have a form with a dropdownbox two listboxes and two buttons on it.

I removed a "select" button as I just used the DropDownList1_SelectedIndexChanged, but the event would not fire until I used the suggestion from: Why DropDownList.SelectedIndexChanged event does not fire?

It involved changing the AutoPostBack='true' and EnableViewState="true" properties

So now the DropDownList works but with the two listboxes, the SelectedIndex stays as -1 and does not change even when selected.

Listbox code:

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

DropDownList Code:

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

Button click event code:

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

The MsgBox now always says no user has been select but there is a user select, very weird.

Any ideas? I think it has something to do with post backs, page_load or the selectedindex changed event of the listbox, it worked perfectly before I made the modifications.

Community
  • 1
  • 1
tread
  • 10,133
  • 17
  • 95
  • 170

1 Answers1

1

The problem was the postback and that the code to populate the listboxes was in a dropbox_load subroutine. This meant that the listbox would repopulate everytime something changed on the page and hence the selecteditem index would revert back to -1.

tread
  • 10,133
  • 17
  • 95
  • 170