Select All Checkbox

In the List view of yii, i want to show a checkbox for each data item. At the top of have a checkbox. When check the top checkbox i want to check all checkbox in list. How it done in yii? Whats the script for this.?

index.php




<?php echo CHtml::form(); ?>

<?php echo CHtml::checkBox("main",false,array('value'=>'','id'=>'check1'));  ?>

<?php $this->widget('zii.widgets.CListView', array(

	'dataProvider'=>$dataProvider,

	'itemView'=>'_view',

        'template' => '{items}{pager}',

)); ?>

<?php echo CHtml::endForm(); ?>



_view.php




<div>

<?php echo CHtml::checkBox("abc[]",false,array('value'=>$data->message_id,'id'=>'sub'));  ?>

<?php echo $data->body; ?>


</div>



Need the client script.

Thanks.

<script>

$(function () {

&#036;('#check1').click(function () {


    &#036;(this).parents('fieldset:eq(0)').find(':checkbox').attr('checked', this.checked);


});

});

</script>

in CGirdView the selectableRows=>2 allows you to check multiple boxes and it puts a check all box at the top.




<?php $this->widget('zii.widgets.grid.CGridView', array (

	'id'=>'user-role-grid',

	'dataProvider'=>$dataprovider,

	'columns'=>array(

		array('header' => 'Roles',

				'value' => '$data->name',

				'htmlOptions'=>array('width:25'),

		),

		array ('class'=>'CCheckBoxColumn',

			'id'=>'check-boxes',

			'value'=>'$data->role_id',

			'htmlOptions'=>array('width:15; text-align: center;'),

			'checked'=>'$data->checkbox',

			'selectableRows'=>2,

        ),                      

	),

));

?>



I was looking for the solution to this problem and the solution posted by haymps saved me . Thank you !!