Click here to Skip to main content
15,906,106 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello to all,

i have a grid on my web page. there are some checkbox according to grid row. i want to set header checkbox in which when i clicked on header checkbox all other checkbox which are in grid row are selected true by automatically and same as when i deselect the header checkbox, all other checkbox are deselect By java Script.

so, please tell me how this thing is done ?
i use the template filed in gridview.

Thanks and Regards ....
Mitesh
Posted
Updated 15-Jun-12 18:48pm
v2
Comments
Code 89 16-Jun-12 1:20am    
go thru my answer which i hav posted a link, its fine example for checkbox,
try...

use this js function it will solve your problem. in this js i assume that checkbox in first column

C#
function SelDeSelAll(chkall,grd)
        {
            for(var rowCount=0;rowCount<grd.children[0].childNodes.length;rowCount++)
            {
                grd.children[0].childNodes[rowCount].children[0].children[0].checked=chkall.checked;
            }
        }
 
Share this answer
 
Try this link...

Checkbox select/deselect

see also below example...

<script type="text/javascript" language="javascript">
function SetAllCheckBoxes(FormName, AreaID, CheckValue)
{
if(!document.forms[FormName])
return;
var objCheckBoxes = document.getElementById(AreaID).getElementsByTagName('input');
if(!objCheckBoxes)
return;
var countCheckBoxes = objCheckBoxes.length;
if(!countCheckBoxes)
objCheckBoxes.checked = CheckValue;
else
for(var i = 0; i < countCheckBoxes; i++)
objCheckBoxes[i].checked = CheckValue;
}
</script>


</head>

<div id="items">
<form name="SelectedItems" action="" method="post">
Select/Unselect All<br>
<div style="background:#ccc;"><input name="checkall" type="checkbox" onclick="SetAllCheckBoxes('SelectedItems','items',this.checked);" /></div><br><br>

<input type="checkbox" name="selected" value="Some text description 1"><input type="hidden" name="selecteditems" value=" "><br>
<input type="checkbox" name="selected" value="Some text description 2"><input type="hidden" name="selecteditems" value=" "><br>
<input type="checkbox" name="selected" value="Some text description 3"><input type="hidden" name="selecteditems" value=" "><br>
<input type="checkbox" name="selected" value="Some text description 4"><input type="hidden" name="selecteditems" value=" "><br>
<input type="checkbox" name="selected" value="Some text description 5"><input type="hidden" name="selecteditems" value=" "><br>
<input type="checkbox" name="selected" value="Some text description 6"><input type="hidden" name="selecteditems" value=" "></div>
</form>

</body>
</html>
</script>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900