Navigation


RSS: Matt Pavey RSS Feed



Tuesday, November 18, 2008 @ 7:32 pm,ASP.Net,Matt Pavey

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>


The opinions expressed on this website are my personal opinions
and do not represent my employer's or my clients' views in any way.