title: How can I set checkboxlist items as checked by default
body: <p>In my page i have a CheckBoxList control and i would like all the checkboxes to be checked by default.  how can i do that?  i have tried couple ways but it is not doing it.  here is my code behind:</p>
  
  <pre><code>protected void chkAll_CheckedChanged(object sender, EventArgs e)
      {
  
          foreach(GridViewRow gr in GridView1.Rows)
          {
  
              CheckBox cb = (CheckBox)gr.FindControl("chkItem");
              cb.Checked = true;
              if(((CheckBox)sender).Checked)
               cb.Checked = true;
                  else
               cb.Checked = false;
          }
  
      }
  </code></pre>
  
  <p>and here is my ASPX code:</p>
  
  <pre><code>&lt;asp:TemplateField HeaderText="Check All"&gt;
                      &lt;HeaderTemplate&gt;
                          &lt;asp:CheckBox ID="chkAll" runat="server" AutoPostBack="True" OnCheckedChanged="chkAll_CheckedChanged" /&gt;
                      &lt;/HeaderTemplate&gt;
                      &lt;ItemTemplate&gt;
                          &lt;asp:CheckBox ID="chkItem" runat="server" /&gt;
                      &lt;/ItemTemplate&gt;
                  &lt;/asp:TemplateField&gt;
  </code></pre>