How to find the control of textbox inside the grid
<p>I am using ASP.NET and I have one <code>GridView</code> that has a <code>TextBox</code> within an editTemplate, but I am not able to find the control; whenever I try to assign the value to <code>TextBox</code> of <code>GridView</code> I'm getting a <code>NullReferenceException</code>. </p>

<p>My code is as follows:</p>

<pre><code>for (int i = 0; i &lt; grdTransfer.Rows.Count; i++)
{
    GridViewRow row = grdTransfer.Rows[i];
    if (((CheckBox)row.FindControl("chkSelect")).Checked)
    {
        count = 1;
        (row.FindControl("txtDestLocation") as TextBox).Text = txtLocation.Text;
    }
}
</code></pre>

<p>Issue: <code>NullReferenceException: object reference not set to the instance of an object</code>.</p>

<p>This means I'm getting <code>null</code> whenever I try to assign the value of <code>GridView</code> <code>TextBox</code> from outside the <code>TextBox</code> at runtime. </p>

<p><em><strong>What am I doing wrong?</em></strong></p>
