CheckBoxList - how to preselect checked state?

  • Thread starter Thread starter Derrick
  • Start date Start date
D

Derrick

Is there any simple way to say "set all items to checked" after a
checkboxlist has been databound? Or to specify which data column to use as
the "checked" state?

Thanks in advance!

Derrick
 
There is no property that you can set for universally setting all the
listitems to true.
However, the no-too-hard way is to loop through the items , after you bind
them to the datasource, and then run through the loop and set the Selected
option to "true".

Code sample :
if(!Page.IsPostBack){
foreach(ListItem li in CheckBoxList1.Items)
{
li.Selected = true;
}
}
 
Back
Top