Reputation: 3396
I'm having a bit of trouble with my CheckBoxList control in ASP.NET - it seems to not store the values that I have checked (?)
This is the test-code I have at the moment:
for (int i = 0; i < cbMemberTypes.Items.Count; i++)
{
if (cbMemberTypes.Items[i].Selected)
{
// do stuff
}
}
I have tried to output the amount of checked items, but it is always returning 0. I'm rather lost here, because in my other usercontrol, it works perfectly! Any hints on this will be greatly appreciated! :-)
Upvotes: 0
Views: 2713
Reputation: 15567
Ditto @Shiraz: check to see if you are binding or setting values in the Page_Load
.
Since Page_Load
fires before the button click event handler, the control is being rebound each time you click and the users' selection is wiped out. Try wrap it in a if(!IsPostBack) { /* bind CBLlist */ }
.
Upvotes: 3