title: how to get row values when checkbox is checked in gridview
body: <p>before I asked this I did some checking around to make sure that this doesn't turn out to be a duplicate and ways to get the row values from a row that has a checkbox in its template field...but I can't seem to get it working...So far I have tried</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
      {
          Entities NW = new Entities();
  
          var customers =
              from c in NW.Customers
              where (c.ContactName.StartsWith("Ma") || c.ContactName.StartsWith("An")
              || c.ContactName.StartsWith("T")
              || c.ContactName.StartsWith("V")
              )
              orderby c.ContactName ascending
              select new
              {
                  c.CustomerID,
                  c.ContactName,
                  c.CompanyName,
                  c.City
              };
  
          gv1.DataSource = customers.ToList();
          gv1.DataBind();
      }
  
      protected void Button1_Click(object sender, EventArgs e)
      {
          foreach (GridViewRow row in gv1.Rows)
          {
              if (row.RowType == DataControlRowType.DataRow)
              {
                  CheckBox chkRow = (row.Cells[0].FindControl("CB") as CheckBox);
                  if (chkRow.Checked)
                  {
                      Label1.Text = row.Cells[2].Text;
                  }
              }
          }
      }
  </code></pre>
  
  <p>I have stepped through the button click event and when it gets to </p>
  
  <blockquote>
    <p>if (chkRow.Checked)</p>
  </blockquote>
  
  <p>its showing as null and skips over it..</p>
  
  <p>my markup is </p>
  
  <pre><code>&lt;asp:GridView ID="gv1" runat="server"&gt;
              &lt;HeaderStyle BackColor="SkyBlue" /&gt;
              &lt;AlternatingRowStyle BackColor="Yellow" /&gt;
              &lt;Columns&gt;
                  &lt;asp:TemplateField&gt;
                      &lt;ItemTemplate&gt;
                          &lt;asp:CheckBox ID="CB" runat="server" /&gt;
                      &lt;/ItemTemplate&gt;
                  &lt;/asp:TemplateField&gt;
              &lt;/Columns&gt;
          &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>when I look at the source after I run, the checkboxes are all named differently than what I gave them the ID of "CB", attached is the pic of the source when its running</p>
  
  <p><img src="https://i.stack.imgur.com/MaiWI.png" alt="Source when ran"></p>
  
  <p>I am not sure what I am doing wrong with this</p>