Monday, June 9, 2008

How to select all checkbox when i select header checkbox in datagrid.

<script language="javascript">
function checkall(obj)
{
var check=obj.checked;
var len=document.form1.elements.length;
for(i=0;i<len;i++)
{
if(document.form1.elements.item(i).type=="checkbox")
{
document.form1.elements.item(i).checked=check;
}
}
}
</script>
In .Aspx grid control..
<Columns>
<asp:TemplateColumn>
<HeaderTemplate>
<input type="checkbox" id="head" onclick="checkall(this)"/>
</HeaderTemplate>
</asp:TemplateColumn>
</Columns>
<Columns>