Accessing asp.net tablerow child control by type
<p>I'm iterating through a collection of asp:tablerows to be able to get or set the text in a textbox that is nested in the third cell of the row; I'm doing this by type rather than by ID because the cell ID's in that column aren't totally consistent--thus I can't really call FindControl() to achieve this. I've resorted to casting the third control in the TableRow to a TableCell and then Casting the first control in that cell to a TextBox. Not quite correct, as I'm getting an index out of range exception thrown. The problem mainly lies in the Controls.Count() property of the third cell, which comes to zero. </p>

<p>Not sure if there's a better way to access the textbox---should I resort to FindControl()?</p>

<p>The code:</p>

<pre><code>foreach (TableRow row in tblProviders.Rows) {

    string value = ((TextBox)((TableCell)row.Controls(2)).Controls(0)).Text;

    ...


}
</code></pre>

<p>My searches here only yielded use of FindControl(), so that may be the only way...</p>

<p>Thanks!</p>
