Monday, June 29, 2009

Pre-selecting items from CheckBoxList

I'm not much of an ASP.NET guy, but from time to time I've got to write some simple ASP.NET pages.

I've tried to use data-bound CheckBoxList (data binding done with the built-in wizard), and update the data with some pre-selected values. For some reason CheckBoxList Items are not populated when Page_Load function is called, so the list can't be updated.

Solution A: Found it on Google, but should have thought about it myself - just remove the data-binding done with the VS wizard, and do all the data handling in code.

Solution B (better): Call 'DataBind()' before pre-selecting the CheckBoxList items.

Weird. I must be missing something here. Anyway - it's working.

No comments: