If i check the header checkbox all the items are getting inserted If i deselt some of the items its not taking it.
if i deselect some items it must not insert inot the checkbox
<asp:TemplateField HeaderText="StateName">
<HeaderTemplate>
<asp:CheckBox ID="checkAll" runat="server" onclick = "checkAll(this);" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBox2" runat="server"/>
</ItemTemplate>
</asp:TemplateField>
foreach (GridViewRow row in GridView1.Rows)
{
//You need to find the control inside GridView header like given below ..check the position of you checkall checkbox ..if its first
//position then write 0 ..
CheckBox chk = GridView1.HeaderRow.Cells[0].FindControl("checkAll") as CheckBox;
// CheckBox cbl = GridView1.Rows.FindControl("CheckBoxList1") as CheckBox;
//CheckBox chk = (CheckBox)GridView1.FindControl("checkAll");
CheckBox mychkbx = row.FindControl("CheckBoxList1") as CheckBox;
// CheckBox cb = (CheckBox)Header.FindControl("checkAll");
// CheckBox cb = (CheckBox)row.FindControl("checkAll");
// CheckBox cbl = (CheckBox)row.FindControl("CheckBoxList1");
Label lbl1 = (Label)row.FindControl("lblfacility");
if (chk.Checked || mychkbx.Checked || chk.Checked&&mychkbx.Checked)
{
string fid = lbl1.Text;
SqlCommand cmd = new SqlCommand();
cmd = new SqlCommand("insert into tblhotelfacility(hotelid,fid,langid,activestatus) values('" + ddlhotel.SelectedValue + "','" + Convert.ToInt32(fid) + "','" + langid + "','" + activestatus + "')", con);
cmd.ExecuteNonQuery();
}