private void page_load(object sender, system.eventargs e)
{
checkboxlist cbl=new checkboxlist();
cbl.id=”cbl”;
cbl.items.add(new listitem(“1″,”1”));
cbl.items.add(new listitem(“2″,”2”));
cbl.items.add(new listitem(“3″,”3”));
this.page.controls[1].controls.add(cbl);
cbl.selectedindexchanged+= new system.eventhandler(this.checkboxlist1_selectedindexchanged);
cbl.autopostback=true;
}
private void checkboxlist1_selectedindexchanged(object sender, system.eventargs e)
{
response.write(“选中项的值:<br>”);
foreach(listitem li in ((checkboxlist)sender).items)
{
if(li.selected)
{
response.write(li.value+”<br>”);
}
}
}