An easy way to check all the Checkbox inside Gridview

vishalneeraj-24503
Posted by vishalneeraj-24503 under JavaScript category on | Points: 40 | Views : 705
If we want to check all Checkboxes which are inside Gridview, then an easy way to do it as below:-

<script type="text/javascript">

function check_all_check_boxes(chk)
{
var grid_employee = document.getElementById('<%=grid_view_employee_details.ClientID %>');

if(grid_employee!=null)
{
for (row_index = 1; row_index <= grid_employee.rows.length-1; row_index++)
{
grid_employee.rows[row_index].cells[0].getElementsByTagName("input")[0].checked = chk.checked;
}
}
}

</script>

//To call this function,

<asp:GridView ID="grid_view_employee_details" runat="server" AllowPaging="true" PageSize="10">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="check_box_header" runat="server" onclick="check_all_check_boxes(this);" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chk_state" runat="server" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

Comments or Responses

Login to post response