Here's an easy way to check or uncheck all items in a CheckBoxList.
JavaScript
function CheckBoxListSelect(cbControl, state)
{
var chkBoxList = document.getElementById(cbControl);
var chkBoxCount = chkBoxList.getElementsByTagName("input");
for(var i=0; i < chkBoxCount.length; i++)
{
chkBoxCount[i].checked = state;
}
return false;
}
ASP.Net CheckBoxList
<div>
<a href="javascript:void(0)" onclick="javascript: CheckBoxListSelect('<%=chkStates.ClientID %>', true)">Select All</a> | <a href="javascript:void(0)" onclick="javascript: CheckBoxListSelect('<%=chkStates.ClientID %>', false)">Select None</a>
</div>
<div>
<asp:CheckBoxList ID="chkStates" RepeatColumns="6" Width="100%" runat="server" />
</div>
0 comments: