Gridview Header Checkbox Select and Deselect using client side JavaScript.

vishalneeraj-24503
Posted by vishalneeraj-24503 under JavaScript category on | Points: 40 | Views : 1121
I am assuming that we have a Gridview control with Checkboxes inside it.

Now,write a javascript code as
<script type="text/javascript" language="javascript">
function Check_UncheckAll(Checkbox)
{
var Grid_vw_Emp = document.getElementById("<%=grid_emp.ClientID %>");

for (i = 1;i<= Grid_vw_Emp.rows.length-1;i++)
{
Grid_vw_Emp.rows[i].cells[0].getElementsByTagName("INPUT")[0].checked = Checkbox.checked;
}
}
</script>


Here,cells[0] means 0 index that is Checkbox index position.
Call above Javascript method on Checkbox OnClick event as:-

<HeaderTemplate>
<asp:CheckBox ID="chkboxSelectAll" runat="server" onclick = "Check_UncheckAll(this);" />
</HeaderTemplate>

Comments or Responses

Login to post response