title: How do I access TextBox controls OUTSIDE of edit/update event?
body: <p>I have tried using FindControl which is what every single StackOverflow topic suggests, and I get an object reference error. Is there no other way? I found one topic where the guy seemed to be having the same problem as me but nobody answered his either.</p>
  
  <p>I am trying to loop through my GridView and do a comparison, but row.Cells[3].Text returns a blank string. I assume this is because I have TextBox controls in my GridView, but when I try to access the TextBox controls OUTSIDE OF AN EDIT/UPDATE event I get an "Object reference not set to instance of object" error. It makes sense to me that I get this error because the TextBox is not "open" at the time I'm looping through the GridView.</p>
  
  <p>So this is my dilemma. I can't get the value the ordinary way (row.Cells[3].Text) and I can't seem to get it by using FindControl either. </p>
  
  <p>Is there some other way I'm supposed to retrieve the value in this case?</p>
  
  <pre><code>foreach (GridViewRow row in GridView1.Rows)
  {
      if (row.Cells[3].Text == storeNumber)
      {
          // blah blah
      }
  }
  </code></pre>
  
  <p>Alternatively,</p>
  
  <pre><code>foreach (GridViewRow row in GridView1.Rows)
  {
      if (row.FindControl("StoreNumberLabel").ToString() == storeNumber)
      {
          // blah blah
      }
  }
  </code></pre>
  
  <p>I have also tried casting the row.FindControl as a TextBox and using .Text instead of .ToString(), but same result. </p>
  
  <p>I have read countless StackOverflow questions about related situations and I cannot find anything that relates to my specific question. If there is a topic that already addresses this, PLEASE link me. I have looked all over the place for a solution to this and cannot find anything.</p>
  
  <p>Update: This is my aspx code</p>
  
  <pre><code>&lt;asp:TemplateField HeaderText="Store"&gt;
      &lt;ItemTemplate&gt;
          &lt;asp:Label ID="StoreNumberLabel" runat="server" Text='&lt;%# Eval("Store") %&gt;'&gt;
          &lt;/asp:Label&gt;
      &lt;/ItemTemplate&gt;
      &lt;EditItemTemplate&gt;
          &lt;asp:TextBox ID="storeNumberTB" runat="server" Text=' &lt;%# Eval("Store")%&gt;'&gt;&lt;/asp:TextBox&gt;
      &lt;/EditItemTemplate&gt;
  &lt;/asp:TemplateField&gt;
  </code></pre>
  
  <p><strong>UPDATE2</strong></p>
  
  <p>I have sort of got it working. The trick is to check if row.FindControl("yourControl") is null. NOT the .Text of the TextBox, but just the row.FindControl().</p>
  
  <p>Problem now is that it doesn't seem to be looking at every row. Only certain ones (which I'm guessing are for some reason the ones that aren't null?).</p>