CheckBoxList - how to preselect checked state?

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
 
G

Guest

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;
}
}
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top