title: How to avoid a page refresh when CheckBox selected in repeater in C#?
body: <p>In an asp.net web page with a repeater control, how can I avoid a complete page refresh when I select a checkbox in the header to check all checkboxes in the item template rows?</p>
  
  <p>My project is based on asp.net C#, with SQL Server as database.</p>
  
  <pre><code>        &lt;asp:Repeater ID="Repeater_product_detail" runat="server" OnItemCommand="Repeater_product_detail_ItemCommand" OnItemDataBound="Repeater_product_detail_ItemDataBound"&gt;
      &lt;HeaderTemplate&gt;
          &lt;table  class="table table-striped table-bordered "&gt;
              &lt;thead&gt;
                  &lt;tr&gt;
                                &lt;td&gt; &lt;asp:CheckBox ID="chk_select" AutoPostBack="true" runat="server" OnCheckedChanged="chk_select_CheckedChanged"/&gt; &lt;/td&gt;
                                &lt;th&gt;SubCategory&lt;/th&gt;
                                &lt;th&gt;Product Name&lt;/th&gt;
                                &lt;th&gt;Product image&lt;/th&gt;
                                &lt;th&gt;Product Price&lt;/th&gt;
                                &lt;th&gt;in stock&lt;/th&gt;
                                &lt;th&gt;Type for&lt;/th&gt;
                                &lt;th&gt;Action&lt;/th&gt;
                     &lt;/tr&gt;                  
              &lt;/thead&gt;
              &lt;tbody&gt;
  
      &lt;/HeaderTemplate&gt;
      &lt;ItemTemplate&gt;
          &lt;tr&gt;
              &lt;td&gt;  
                   &lt;asp:CheckBox ID="chkDelete" AutoPostBack="true"  runat="server" /&gt; 
                   &lt;asp:Label ID="lbl_id" Visible="false" runat="server" Text='&lt;%# ("int_product_id") %&gt;'&gt;&lt;/asp:Label&gt;
              &lt;/td&gt;
               &lt;td&gt; 
                   &lt;asp:Label ID="lbl_sub_cate" runat="server" Text='&lt;%# Eval("txt_sub_category_name") %&gt;'&gt;&lt;/asp:Label&gt;
                   &lt;asp:DropDownList ID="ddl_sub_category" Width="100px" CommandArgument='&lt;%# DataBinder.Eval(Container.DataItem, "txt_sub_category_name") %&gt;' runat="server" Visible="false" &gt; &lt;/asp:DropDownList&gt;
  
               &lt;/td&gt;
  
              &lt;td&gt; &lt;asp:Label ID="lbl_product_name" runat="server" Text='&lt;%# Eval("txt_product_name") %&gt;'&gt;&lt;/asp:Label&gt;
              &lt;asp:TextBox ID="txt_product_name" BackColor="#d4d0c8" runat="server" Text='&lt;%# DataBinder.Eval(Container.DataItem, "txt_product_name")%&gt;' Visible="false"&gt;&lt;/asp:TextBox&gt;
              &lt;/td&gt;
  
              &lt;td&gt; &lt;%--&lt;asp:Label ID="lbl_product_image" runat="server" Text='&lt;%# Eval("product_img_small") %&gt;'&gt;&lt;/asp:Label&gt;--%&gt;
                    &lt;asp:Image ID="Image1" Height="50px" Width="50px" ImageUrl='&lt;%# Eval("product_img_small") %&gt;' runat="server" /&gt;
              &lt;/td&gt;
  
  
              &lt;td&gt; &lt;asp:Label ID="lbl_product_price" runat="server" Text='&lt;%# Eval("txt_product_price") %&gt;'&gt;&lt;/asp:Label&gt;
               &lt;asp:TextBox ID="txt_product_price" Width="60px" BackColor="#d4d0c8" runat="server" Text='&lt;%# DataBinder.Eval(Container.DataItem, "txt_product_price")%&gt;' Visible="false"&gt;&lt;/asp:TextBox&gt;
              &lt;/td&gt;
              &lt;td&gt; &lt;asp:Label ID="lbl_stock" runat="server" Text='&lt;%# Eval("in_stock") %&gt;'&gt;&lt;/asp:Label&gt;
               &lt;asp:TextBox ID="txt_stock" BackColor="#d4d0c8" Width="60px" runat="server" Text='&lt;%# DataBinder.Eval(Container.DataItem, "in_stock")%&gt;' Visible="false"&gt;&lt;/asp:TextBox&gt;
              &lt;/td&gt;
              &lt;td&gt; &lt;asp:Label ID="lbl_type" runat="server" Text='&lt;%# Eval("cate_type") %&gt;'&gt;&lt;/asp:Label&gt;
              &lt;asp:DropDownList ID="ddl_type" runat="server" Width="60px" DataTextField="cate_type" Visible="false"&gt;&lt;/asp:DropDownList&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;asp:LinkButton ID="lnk_edit" CommandArgument='&lt;%# Eval("int_product_id") %&gt;' CommandName="edit" runat="server"&gt;Edit&lt;/asp:LinkButton&gt;
                   &lt;asp:LinkButton ID="lnk_update" CommandArgument='&lt;%# Eval("int_product_id") %&gt;' Visible="false" CommandName="update" runat="server"&gt;Update&lt;/asp:LinkButton&gt;
                   &lt;asp:LinkButton ID="lnk_cancel" CommandArgument='&lt;%# Eval("int_product_id") %&gt;' Visible="false" CommandName="cancel" runat="server"&gt;Cancel&lt;/asp:LinkButton&gt;
                   &lt;asp:LinkButton ID="lnk_delete" CommandArgument='&lt;%# Eval("int_product_id") %&gt;' CommandName="delete" OnClientClick='javascript:return confirm("Are you sure you want to delete?")'  runat="server"&gt;Delete&lt;/asp:LinkButton&gt;
  
              &lt;/td&gt;
  
  
          &lt;/tr&gt;
      &lt;/ItemTemplate&gt;
  
      &lt;FooterTemplate&gt;
               &lt;tr style="background-color:#15880a"&gt;
               &lt;td colspan="8"&gt; 
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/FooterTemplate&gt;
  
  &lt;/asp:Repeater&gt;
  &lt;asp:LinkButton ID="lnk_del_selected" CommandArgument='&lt;%# Eval("int_product_id") %&gt;'  OnClientClick='javascript:return confirm("Are you sure you want to delete?")' runat="server" OnClick="lnk_del_selected_Click"&gt;Deleted Selected&lt;/asp:LinkButton&gt;
  </code></pre>
  
  <blockquote>
    <p>Behind Code</p>
  </blockquote>
  
  <pre><code>      protected void chk_select_CheckedChanged(object sender, EventArgs e)
  {
      Control header_control = Repeater_product_detail.Controls[0].Controls[0];   // Find header Template's Items
  
      CheckBox chk = header_control.FindControl("chk_select") as CheckBox;
      if (!chk.Checked)
              {
                  toggleCheckState(false);
              }
              else
              {
                  toggleCheckState(true);
              }
  }
  </code></pre>
  
  <p>public void toggleCheckState(bool checkstate)
     {</p>
  
  <pre><code>   foreach (RepeaterItem item in Repeater_product_detail.Items)   // Find Item Template's Items
     {
         if (item.ItemType == ListItemType.AlternatingItem || item.ItemType == ListItemType.Item)
         {
             CheckBox chk_delete = (CheckBox)item.FindControl("chkDelete");
             chk_delete.Checked = checkstate;
         }
     }
  </code></pre>