You could get the TextBox control inside the corresponding cell of the GridView, using the Controls
property or the FindControl(string id)
method:
TextBox txtTotal = gv.Rows[index].cells[0].Controls[0] as TextBox;
or
TextBox txtTotal = gv.Rows[index].cells[0].Controls[0].FindControl("TOTAL") as TextBox;
where index could be 0 for the first row, or an iterator inside a for loop.
Alternatively, you can use a foreach loop over the GridView's rows:
foreach(GridViewRow row in gv.Rows)
{
TextBox txtTotal = row.cells[0].Controls[0].FindControl("TOTAL") as TextBox;
string value = txtTotal.Text;
// Do something with the textBox's value
}
Besides, you have to keep in mind that, if you're creating the GridView dynamically (and not declaratively in the web form), you won't be able to get this control after a page postback.
There is a great 4 Guys from Rolla article on the subject: Dynamic Web Controls, Postbacks, and View State
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…