title: null value in findcontrol of gridview, item template confusion
body: <p>I have Template Field for gridview as below:</p>
  
  <pre><code>&lt;asp:TemplateField ShowHeader="False"&gt;
              &lt;EditItemTemplate&gt;
              &lt;asp:TextBox ID="txtEmpName" runat="server"&gt;&lt;/asp:TextBox&gt;
                  &lt;asp:TextBox ID="txtBonus" runat="server"&gt;&lt;/asp:TextBox&gt;
                  &lt;asp:TextBox ID="txtID" runat="server"&gt;&lt;/asp:TextBox&gt;
              &lt;/EditItemTemplate&gt;
                      &lt;EditItemTemplate&gt;
                          &lt;asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="True" 
                              CommandName="Update" Text="Update"&gt;&lt;/asp:LinkButton&gt;
                          &amp;nbsp;&lt;asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" 
                              CommandName="Cancel" Text="Cancel"&gt;&lt;/asp:LinkButton&gt;
                      &lt;/EditItemTemplate&gt;
                      &lt;ItemTemplate&gt;
                          &lt;asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" 
                              CommandName="Edit" Text="Edit"&gt;&lt;/asp:LinkButton&gt;
  
                      &lt;/ItemTemplate&gt;
                  &lt;/asp:TemplateField&gt;
  </code></pre>
  
  <p>When i am in <code>gv_RowUpdating</code> event, i wanted to take the value of edited field by findcontrol.</p>
  
  <p>For that i am using following code:</p>
  
  <pre><code>`TextBox txtUname = (TextBox)gv.Rows[e.RowIndex].FindControl("txtEmpName");`
  </code></pre>
  
  <p>But each time it is showing me <code>null</code> value in <code>txtUname</code> when i debug the code.</p>
  
  <p>What can be the problem?</p>
  
  <p>Full Event Code:</p>
  
  <pre><code> protected void gv_RowUpdating(object sender, GridViewUpdateEventArgs e)
          {
              try
              {
  
                  TextBox txtUname = (TextBox)gv.Rows[e.RowIndex].FindControl("txtEmpName");
  
                  float bonus = float.Parse(gv.DataKeys[e.RowIndex].Values["bonus"].ToString());
  
                  try
                  {
                      cmd = new SqlCommand("update emp set empName=@eName");
                      cmd.parameters.AddParametersWithValue("@eName",txtUname.Text);
                      cmd.ExecuteNonQuery();
                  }
                  catch (Exception ex)
                  {
                  }
              }
              catch (Exception ex)
              {
              }
  
          }
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
          {
  
              con = new SqlConnection("Data Source=192.168.51.71;Initial Catalog=WebBasedNewSoft;User ID=sa;password=prabhu");
  
              BindGrid();
          }
          private void BindGrid()
          {
              try
              {
                  da = new SqlDataAdapter("select * from emp", con);
                  DataSet ds = new DataSet();
                  da.Fill(ds);
                  GridView1.DataSource = ds.Tables[0];
                  GridView1.DataBind();
              }
              catch (Exception ex)
              {
              }
          }
          protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
          {
              int index = GridView1.EditIndex;
  
              GridViewRow row = GridView1.Rows[index];
  
              string eName = ((TextBox)row.Cells[2].Controls[0]).Text.ToString().Trim();
  
              try
              {
                  con.Open();
                  cmd = new SqlCommand("update emp set empName='"+eName+"'",con);
                  cmd.ExecuteNonQuery();
                  con.Close();
              }
              catch(Exception ex)
              {
              }
  
          }
  
          protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
          {
              GridView1.EditIndex = e.NewEditIndex;
              BindGrid();
          }
      }
  </code></pre>