here is a sample i've used check it and modify as per your requirement
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="empid" DataSourceID="ObjectDataSource1">
<Columns>
<asp:TemplateField HeaderText="empid" SortExpression="empid">
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("empid") %>'></asp:Label>
</EditItemTemplate>
<HeaderTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="True"
oncheckedchanged="CheckBox1_CheckedChanged" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBox2" runat="server" Text='<%# Eval("empid") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="empname" SortExpression="empname">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("empname") %>'></asp:TextBox>
</EditItemTemplate>
<HeaderTemplate>
<asp:CheckBox ID="CheckBox4" runat="server" AutoPostBack="True"
oncheckedchanged="CheckBox4_CheckedChanged" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBox3" runat="server" Text='<%# Eval("empname") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="age" HeaderText="age" SortExpression="age" />
</Columns>
</asp:GridView>
C# code for that
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
CheckBox cb1selall = GridView1.HeaderRow.FindControl("CheckBox1") as CheckBox;
for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox cb1 = GridView1.Rows[i].FindControl("CheckBox2") as CheckBox;
if (cb1selall.Checked)
{
cb1.Checked = true;
}
else
{
cb1.Checked = false;
}
}
}
protected void CheckBox4_CheckedChanged(object sender, EventArgs e)
{
CheckBox cb2selall = GridView1.HeaderRow.FindControl("CheckBox4") as CheckBox;
for (int i = 0; i < GridView1.Rows.Count; i++)
{
CheckBox cb1 = GridView1.Rows[i].FindControl("CheckBox3") as CheckBox;
if (cb2selall.Checked)
{
cb1.Checked = true;
}
else
{
cb1.Checked = false;
}
}
}