Click here to Skip to main content
16,019,595 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
I use the following code for " Select all checkbox in Repeater by selecting one checkbox" it work for all page. But i wants it work single page as like email inbox.

C#
protected void chkSelectAll_CheckedChanged(object sender, EventArgs e)
       {
           CheckBox chkboxAll = (CheckBox)sender;

           foreach (RepeaterItem item in rptOscarNominees.Items)
           {
               CheckBox chkbox = (CheckBox)item.FindControl("chkSelect");
               chkbox.Checked = chkboxAll.Checked;
           }
       }
Posted

1 solution

Use the below code:

XML
<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>


XML
<div id="items">
<form name="SelectedItems" action="" method="post">
<b>Select/Unselect All</b><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=" "><br>
</div>
 
Share this answer
 

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