create this event on .cs page
-----------------------------
protected void ChkOne_CheckedChanged(object sender, EventArgs e)
{
bool flag = true;
for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox chk = (CheckBox)GridView1.Rows[i].FindControl("ChkOne");
if(!chk.Checked)
{
flag = false;
break;
}
}
((CheckBox)GridView1.HeaderRow.FindControl("ChkAll")).Checked = flag;
}
replace item template code on .aspx page
----------------------------------------
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
CssClass="data" Width="50%" AllowSorting="True" DataSourceID="dsDetails"
AllowPaging="True" PageSize="5">
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="ChkAll" runat="server" AutoPostBack="true" oncheckedchanged="ChkAll_CheckedChanged"/>
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="ChkOne" runat="server" AutoPostBack="true" oncheckedchanged="ChkOne_CheckedChanged"/>
</ItemTemplate>
</asp:TemplateField>
</asp:GridView>