Nor Azlina Mahmud

Nor Azlina Mahmud

  • NA
  • 23
  • 9.2k

Uncheck all checkbox still maintain check when data value 1

Apr 2 2013 10:41 PM
I have a select all checkbox at gridview header. I manage to do select all function but when uncheck all, it uncheck all checkbox including the data that has value 1.  I want it to be when I uncheck all, the data that value 1 still check. how do I do that.. below the image is my sample code...
also how to make the checkbox text stays the same line as checkbox...
Tq so much..



<asp:TemplateField HeaderText="">
  <HeaderTemplate>
  <asp:CheckBox ID="chkSelectAllGeneral" runat="server" Text="GENERAL" 
  Font-Size="Smaller" AutoPostBack="true"
  OnCheckedChanged="chkSelectAllGeneral_CheckedChanged" /> 
  </HeaderTemplate>
  <ItemTemplate>
      <asp:CheckBox ID="chkgeneral" AutoPostBack="true"  runat="server" />
  </ItemTemplate>
</asp:TemplateField>


protected void chkSelectAllGeneral_CheckedChanged(object sender, EventArgs e)
{
  foreach (GridViewRow rowItem in GridView3.Rows)
  {
  CheckBox chkgeneral = (CheckBox)(rowItem.Cells[0].FindControl("chkgeneral"));
  chkgeneral.Checked = ((CheckBox)sender).Checked; 
  }
}

Answers (1)