title: How to fix code have select all asp:CheckBoxList within current table only in .NET C# same as "JQuery - Select All CheckBoxes within..." question?
body: <p>How to fix code have select all <strong>asp:CheckBoxList</strong> within current table only in .NET C# same as "JQuery - Select All CheckBoxes within current table only" question ?</p>
  
  <p>Because I try coding with sample but can't select all <strong>asp:CheckBoxList</strong> within current table only.</p>
  
  <p>Link to <a href="https://stackoverflow.com/questions/1742010/jquery-select-all-checkboxes-within-current-table-only/1742792">"JQuery - Select All CheckBoxes within current table only"</a>  question.</p>
  
  <p>My snipplet to describe problem.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  
  &lt;script
      type="text/javascript"
      src="//code.jquery.com/jquery-1.6.4.js"&gt;&lt;/script&gt;
  
  &lt;style&gt;
  form , p , td, th{
    font-size: 24px;
  }
  input.largerCheckbox
  {
    width: 22px;
    height: 22px;
  }
  &lt;/style&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;h1&gt;Show checkboxes:&lt;/h1&gt;
  
  &lt;p&gt;&lt;label&gt;&lt;input type="checkbox" class="largerCheckbox" id="checkAll"/&gt; Check all&lt;/label&gt;&lt;/p&gt;
  
  &lt;input type="text" id="myInput" onkeyup="myFunction()" placeholder="Search for names.." title="Type in a name"&gt;&lt;br&gt;&lt;br&gt;
  
  &lt;table id="myTable"&gt;
    &lt;tr class="header"&gt;
      &lt;th&gt;Checkbox&lt;/th&gt;
      &lt;th&gt;Number&lt;/th&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;input type="checkbox" class="largerCheckbox" name="vehicle1" value="1"&gt;&lt;/td&gt;
      &lt;td&gt;1&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;input type="checkbox" class="largerCheckbox" name="vehicle2" value="11"&gt;&lt;/td&gt;
      &lt;td&gt;11&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;input type="checkbox" class="largerCheckbox" name="vehicle3" value="111"&gt;&lt;/td&gt;
      &lt;td&gt;111&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;input type="checkbox" class="largerCheckbox" name="vehicle4" value="1111"&gt;&lt;/td&gt;
      &lt;td&gt;1111&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;input type="checkbox" class="largerCheckbox" name="vehicle5" value="11111"&gt;&lt;/td&gt;
      &lt;td&gt;11111&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/table&gt;
  
  &lt;script&gt;
  function myFunction() {
    var input, filter, table, tr, td, i, txtValue;
    input = document.getElementById("myInput");
    filter = input.value.toUpperCase();
    table = document.getElementById("myTable");
    tr = table.getElementsByTagName("tr");
    for (i = 0; i &lt; tr.length; i++) {
      td = tr[i].getElementsByTagName("td")[1];
      if (td) {
        txtValue = td.textContent || td.innerText;
        if (txtValue.toUpperCase().indexOf(filter) &gt; -1) {
          tr[i].style.display = "";
        } else {
          tr[i].style.display = "none";
        }
      }       
    }
  }
  &lt;/script&gt;
  
  &lt;script&gt;
  $("#checkAll").change(function () {
      $("input:checkbox").prop('checked', $(this).prop("checked"));
  });
  &lt;/script&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>My full source code.</p>
  
  <p><a href="https://github.com/doanga2007/CheckLoopQR3" rel="nofollow noreferrer">https://github.com/doanga2007/CheckLoopQR3</a></p>
  
  <p>Sample code at the bottom.</p>
  
  <ol>
  <li>Default.aspx (HTML Code)</li>
  </ol>
  
  <pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="CheckLoopQR3.Default" %&gt;
  
  &lt;!DOCTYPE html&gt;
  
  &lt;html&gt;
  &lt;head runat="server"&gt;
      &lt;title&gt;&lt;/title&gt;
      &lt;link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"&gt;
      &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"&gt;&lt;/script&gt;
      &lt;script type="text/javascript" src="//code.jquery.com/jquery-1.6.4.js"&gt;&lt;/script&gt;
      &lt;script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"&gt;&lt;/script&gt;
  
  &lt;style&gt;
      #myInput {
          font-size: 16px;
          padding: 6px 20px 6px 10px;
          border: 1px solid #ddd;
          margin-bottom: 3px;
      }
  &lt;/style&gt;
  
      &lt;script type="text/javascript"&gt;
      $(window).load(function(){
      $("#checkAll").change(function () {
      $("input:checkbox").prop('checked', $(this).prop("checked"));
      });
      });
      &lt;/script&gt;
      &lt;script&gt;
          function myFunction() {
              var input, filter, table, tr, td, i, txtValue;
              input = document.getElementById("myInput");
              filter = input.value.toUpperCase();
              table = document.getElementById("CheckBox1");
              tr = table.getElementsByTagName("tr");
              for (i = 0; i &lt; tr.length; i++) {
                  td = tr[i].getElementsByTagName("td")[0];
                  if (td) {
                      txtValue = td.textContent || td.innerText;
                      if (txtValue.toUpperCase().indexOf(filter) &gt; -1) {
                          tr[i].style.display = "";
                      } else {
                          tr[i].style.display = "none";
                      }
                  }
              }
          }
      &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form id="form1" runat="server"&gt;
          &lt;div class="container"&gt;
              &lt;h2&gt;QR Code Generator&lt;/h2&gt;
              &lt;div class="row"&gt;
                  &lt;div class="col-md-4"&gt;
                      &lt;div class="form-group"&gt;
                          &lt;label&gt;Please Input Data&lt;/label&gt;
                          &lt;div class="input-group"&gt;
                              &lt;asp:TextBox ID="txtQRCode" runat="server" CssClass="form-control"&gt;&lt;/asp:TextBox&gt;
                              &lt;div class="input-group-prepend"&gt;
                                  &lt;asp:Button ID="btnGenerate" runat="server" CssClass="btn btn-secondary" Text="Generate" OnClick="btnGenerate_Click" /&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
  
              &lt;asp:Button ID="btnSelect" runat="server" CssClass="btn btn-secondary" Text="Display Text" OnClick="btnSelect_Click" /&gt;&lt;br /&gt;&lt;br /&gt;
  
              &lt;asp:PlaceHolder ID="PlaceHolder1" runat="server"&gt;&lt;/asp:PlaceHolder&gt;
  
              &lt;asp:CheckBox ID="checkAll" runat="server" Font-Size="Large"/&gt;&lt;asp:Label id="checkTextAll" runat="server" Font-Size="Large"&gt;&lt;/asp:Label&gt;&lt;br /&gt;&lt;br /&gt;
  
              &lt;label&gt;Input Number to Search &amp;nbsp;&amp;nbsp;&lt;/label&gt;
              &lt;input type="text" id="myInput" onkeyup="myFunction()"&gt;&lt;br /&gt;&lt;br /&gt;
  
              &lt;asp:CheckBoxList ID="CheckBox1" runat="server" Border="1"
              BorderColor="LightGray" Font-Size="Large"&gt;&lt;/asp:CheckBoxList&gt;  
  
          &lt;/div&gt;
      &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <ol start="2">
  <li>Default.aspx.cs (C# Code)</li>
  </ol>
  
  <pre><code>using System;
  using System.Drawing;
  using System.IO;
  using ZXing;
  using ZXing.QrCode;
  using System.Web.UI.WebControls;
  using System.Web.UI.HtmlControls;
  
  namespace CheckLoopQR3
  {
      public partial class Default : System.Web.UI.Page
      {
          protected void Page_Load(object sender, EventArgs e)
          {
              this.checkTextAll.Text = " Check All";
          }
          protected void btnSelect_Click(object sender, EventArgs e)
          {
              string code = txtQRCode.Text;
              long num = Convert.ToInt64(code);
  
              int i;
  
              for (i = 1; i &lt; 6; i++)
              {
                  num *= i;
                  CheckBox1.Items.Add(new ListItem(" " + num));
              }
          }
          protected void btnGenerate_Click(object sender, EventArgs e)
          {
              if (CheckBox1.SelectedItem == null)
              {
                  Response.Redirect("Default.aspx");
              }
  
              string[] texture = { "Selected Text 1 -&gt; ", "Selected Text 2 -&gt; ", "Selected Text 3 -&gt; ",
                                   "Selected Text 4 -&gt; ", "Selected Text 5 -&gt; "};
  
              string[] texture2 = { " is Checkbox 1.", " is Checkbox 2.", " is Checkbox 3.",
                                   " is Checkbox 4.", " is Checkbox 5."};
  
              foreach (ListItem listItem in CheckBox1.Items)
              {
                  if (listItem.Selected)
                  {
                      int a = CheckBox1.Items.IndexOf(listItem);
                      a = a + 1;
  
                      string code = listItem.Text;
  
                      CheckBox1.Visible = false;
                      checkAll.Visible = false;
                      checkTextAll.Visible = false;
  
                      QrCodeEncodingOptions options = new QrCodeEncodingOptions();
  
                      options = new QrCodeEncodingOptions
                      {
                          DisableECI = true,
                          CharacterSet = "UTF-8",
                          Width = 150,
                          Height = 150,
                          Margin = 0,
                      };
  
                      var barcodeWriter = new BarcodeWriter();
                      barcodeWriter.Format = BarcodeFormat.QR_CODE;
                      barcodeWriter.Options = options;
  
                      System.Web.UI.WebControls.Image imgBarCode = new System.Web.UI.WebControls.Image();
                      imgBarCode.Height = 150;
                      imgBarCode.Width = 150;
  
                      Label lblvalues = new Label();
                      lblvalues.Text += texture[a - 1] + listItem.Text + texture2[a - 1];
                      lblvalues.Font.Size = FontUnit.Large;
  
                      using (Bitmap bitMap = barcodeWriter.Write(code))
                      {
                          using (MemoryStream ms = new MemoryStream())
                          {
                              bitMap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                              byte[] byteImage = ms.ToArray();
                              imgBarCode.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(byteImage);
                          }
                          PlaceHolder1.Controls.Add(imgBarCode);
                          PlaceHolder1.Controls.Add(new HtmlGenericControl("br"));
                          PlaceHolder1.Controls.Add(lblvalues);
                          PlaceHolder1.Controls.Add(new HtmlGenericControl("br"));
                      }
                  }
                  else
                  {
                      //do something else 
                  }
              }
          }
      }
  }
  </code></pre>