Web Listbox and Selected in C#

G

Guest

I have a problem with the Listbox Web control in C#. It works fine in VB but in C#, the .Selected property always returns false for some reason. I have the Listbox Selectionmode set to Multiple. Can anyone tell me why? This is in Visual Studio.NET 2002

Code

foreach ( ListItem oItem in lstPeriods.Items

if ( oItem.Selected == true ) // This always returns false
 
C

Chris Jackson

Well, the short answer is that it shouldn't do this. Now, we just need to
figure out why. When is this code being executed? Do you have the right
number of items? Are you databinding the control again prior to iterating
through it, in which case the framework will see it as fresh with no items
selected?
 
G

Guest

This code is being executed in the handler for a submit button.
The listbox control is databound to an OracleDataReader. I see the data in the listbox fine, make my seletion(s) and press the submit button.

public class DateRange : System.Web.UI.Pag

protected System.Web.UI.WebControls.Button btnSubmit
protected System.Web.UI.WebControls.ListBox lstPeriods
..

private void btnSubmit_Click(object sender, System.EventArgs e


foreach ( ListItem oItem in lstPeriods.Items

if ( oItem.Selected == true ) // this is always fals

..

Thanks for your help, --David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top