Hi , Hope it help you
protected void DataGrid1_ItemCreated(object sender, DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Header)
{
}
}
protected void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Header)
{
if (((CheckBox)e.Item.FindControl("CheckBox2")).Checked == true)
{
Response.Write("<script>alert('Checked')</script>");
}
else if (((CheckBox)e.Item.FindControl("CheckBox2")).Checked == false)
{
Response.Write("<script>alert('NOT Checked')</script>");
}
}
}
protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
{
if (((CheckBox)sender).Checked == true)
{
Response.Write("<script>alert('Checked')</script>");
}
else
{
Response.Write("<script>alert('NOT Checked')</script>");
}
}
<asp:DataGrid ID="DataGrid1" runat="server"
DataSourceID="SqlDataSource1" onitemcreated="DataGrid1_ItemCreated"
onitemdatabound="DataGrid1_ItemDataBound" ClientIDMode="Static" >
<Columns>
<asp:TemplateColumn HeaderText="test">
<HeaderTemplate >
<asp:CheckBox ID="CheckBox2" runat="server" ClientIDMode="Static"
oncheckedchanged="CheckBox2_CheckedChanged" />
</HeaderTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>