среда, 20 июля 2011 г.

Check uncheck all checkboxes in a gridview using javascript

Step 1:

Put this script below head tag

<script type="text/javascript" language="javascript">

function changeCheckState(chk)
{
var frm = document.forms[0];
for (i=0; i<frm.length; i++)
{
if (frm.elements[i].id.indexOf('checkBox') != -1)
{
frm.elements[i].checked = chk;
}
}
}

</script>

Step :2

Put this checkbox in header template

<asp:CheckBox ID="checkBox" runat="server" />

Step 3:

Put this checkbox in Itemtemplate

<input id="changeCheckStateId" onclick="changeCheckState(this.checked);" runat="server" type="checkbox" />

Комментариев нет: