It can be done using Javascript. The Code goes Here:
<script >
function checkall(source) {
var checkboxes=new Array();
checkboxes= document.getElementsByTagName('input');
for(var i=0;i<checkboxes.length;i++)
{
if(checkboxes[i].type=='checkbox')
{
checkboxes[i].checked = source.checked;
}
}
}
</script>
<input type="checkbox" onClick="checkall(this)" /> Check All
<input type="checkbox" name="foo[]" value="1"> 1
<input type="checkbox" name="foo[]" value="2"> 2
<input type="checkbox" name="foo[]" value="3"> 3
<input type="checkbox" name="foo[]" value="4"> 4