Only the first ListItem is selected in a ListBox

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a WebForm with a ListBox in it. This SelectionMode is set to Multiple.

When a button is clicked, I check what items are selected using:

foreach (ListItem itm in lb.Items)
{
Trace.Write(itm.Text + ": " + itm.Selected);
}

The trace shows that only the first one selected no matter which items I actually selected in the ListBox.

Anyone has any idea why?
 
Check inside the page_load. Don't do a Databind for your
dropdown when the page is postback.
-----Original Message-----
I have a WebForm with a ListBox in it. This
SelectionMode is set to Multiple.
When a button is clicked, I check what items are selected using:

foreach (ListItem itm in lb.Items)
{
Trace.Write(itm.Text + ": " + itm.Selected);
}

The trace shows that only the first one selected no
matter which items I actually selected in the ListBox.
 
Back
Top