views:

475

answers:

2

I have in a page a databound checklistbox which is populated with data on OnLoad page's event, and also a button.

If the user clicks the button, I must recolect the checkboxes selected inside the checklistbox and do some processing.

But when I iterate over the checklistbox items collection all items have their Selected property set to false, always.

How can I know which items were selected by the user?

+1  A: 

Two things could be going wrong I think.

  • One is that you're data binding your checklistbox each time on in Page_Load. You need to check for !this.IsPostBack if that's the case and only databind it once.
  • The other is that your page or control might have EnableViewState="false", in which case you need to remove it.
fung
+1  A: 

Sounds like you're binding the list in every postback, you should only do it when the user enters the page, when Page.IsPostBack is false:

protected void Page_Load(object sender, EventArgs e)
{
    if (IsPostBack)
    {
        // Bind the list...
    }
}
CMS