Use this code:
function SelectAll(id)
{
var grid = document.getElementById("<%= GridView1.ClientID %>");
var cell;
if(grid.rows.length>0)
{
for(i = 1;i<GridView1.rows.length;i++)
{
cell = grid.rows[i].cells[2];
for(j=0;j<cell.childNodes.length;j++)
{
if(cell.childNodes[j].type=="checkbox")
{
cell.childNodes[j].checked=id.checked;
}
}
}
}
}
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="Checkall" runat="server" onclick="javascript:SelectAll(this);" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="Chkselect" runat="server" />
</ItemTemplate>
</asp:TemplateField>