An easy way to check all the Checkbox inside Gridview

Posted by vishalneeraj-24503 under JavaScript category on | Points: 40 | Views : 678
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 %>');

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;


//To call this function,

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

Comments or Responses

Login to post response