I have a .net Gridview in which "Select All" checkbox has been added to select all the rows available in grid. Below is my Grid code
<asp:TemplateColumn>
<HeaderTemplate>
<input id="chkAll" type="checkbox" onclick="CheckAllDataGridCheckBoxes('chkItem',this.checked)">
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkItem" runat="server"></asp:CheckBox>
</ItemTemplate>
and here is my javascript code
<script type="text/javascript">
function CheckAllDataGridCheckBoxes(aspCheckBoxID, checkVal)
{
re = new RegExp(':' + aspCheckBoxID + '$') //generated control name starts with a colon
for(i = 0; i < Form1.elements.length; i++)
{
elm = document.forms[0].elements[i]
if (elm.type == 'checkbox')
{
if (re.test(elm.name))
elm.checked = checkVal
}
}
}
</script>
Now, the problem is that i am getting error at line for(i = 0; i < Form1.elements.length; i++)
causing my rows remains unselected. What's wrong here?
Aucun commentaire:
Enregistrer un commentaire