title: ASP.NET Delete Multiple GridView rows via Checkbox template
body: <p>I have a GirdView table in my application. I have a <strong>Delete</strong> link button and a checkbox in my first column. Below are snapshots:</p>
  
  <p><img src="https://i.stack.imgur.com/3gMKx.png" alt="enter image description here"><img src="https://i.stack.imgur.com/46tu9.png" alt="enter image description here"></p>
  
  <p>I can manually delete each row by clicking <strong>Delete</strong> link button on each row.</p>
  
  <p>However, I would want to enable the checkbox to delete multiple rows.</p>
  
  <p>Below is my code for my <strong>Delete</strong> link button:</p>
  
  <pre><code>LinkButton lnk = (LinkButton)sender; 
          string stid = lnk.CommandArgument.ToString();
          SqlConnection conn = new SqlConnection("Data Source=DATASOURCE");
          string sql = string.Format("DELETE FROM [UserDB] where Employee like '%{0}%'",stid);
          SqlCommand cmd = new SqlCommand(sql,conn);
          conn.Open();
          cmd.ExecuteNonQuery();
  </code></pre>
  
  <p>Below is my code for the current <strong>Delete Checked</strong> button:</p>
  
  <pre><code>bool atLeastOneRowDeleted = false;
          foreach (GridViewRow row in GridView1.Rows)
          {
              // Access the CheckBox
              CheckBox cb = (CheckBox)row.FindControl("UserSelection");
              if (cb != null &amp;&amp; cb.Checked)
              {
                  atLeastOneRowDeleted = true;
                  // How do I get the value from my Employee column?
                  string userID = ???;
  
  
             SqlConnection conn = new SqlConnection("Data Source=DATASOURCE");
             string sql = string.Format("DELETE FROM [UserDB] where Employee like '%{0}%'",userID);
             SqlCommand cmd = new SqlCommand(sql,conn);
             conn.Open();
             cmd.ExecuteNonQuery();
              }
          }
  </code></pre>
  
  <p>I would like to know how should I grep userID, which is <code>Employee</code> key in the GridView, to <code>INSERT</code> it into my SQL delete statement?</p>