select all the checkboxes in a gridview with row wise

<asp:TemplateField> 
 <HeaderTemplate> 
  <asp:CheckBox ID="CheckAllAccept" runat="server" Text="ACCEPT" onclick="checkAll(this, 'CheckAccept');" /> 
 </HeaderTemplate> 
 <ItemTemplate> 
  <asp:CheckBox ID="CheckAccept" runat="server" onclick="Check_Click(this)"/> 
 </ItemTemplate> 
</asp:TemplateField> 
<asp:TemplateField> 
 <HeaderTemplate> 
  <asp:CheckBox ID="CheckAllReject" runat="server" Text="ACCEPT" onclick="checkAll(this, 'CheckReject');" /> 
 </HeaderTemplate> 
 <ItemTemplate> 
  <asp:CheckBox ID="CheckReject" runat="server" onclick="Check_Click(this)"/> 
 </ItemTemplate> 
</asp:TemplateField> 
<script type=text/javascript>
<!--
function checkAll(elementRef, checkBoxId)
{
 var gridRef = document.getElementById('<%= GridView1.ClientID %>');
 var inputElementArray = gridRef.getElementsByTagName('input');
 var isChecked = elementRef.checked;
 for (var i=0; i<inputElementArray.length; i++)
 {
  var inputElement = inputElementArray[i];
  if ( (inputElement.type == 'checkbox') && (inputElement.id.indexOf(checkBoxId) >= 0) )
   inputElement.checked = isChecked;
 }
}
// -->
</script>

0 comments:

Post a Comment