我只想知道最后两行之间的区别
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
if (GridView1.Rows[e.RowIndex].RowType == DataControlRowType.DataRow)
{
GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex];
string lstnme = ((TextBox)row.Cells[2].FindControl("txtLstNme")).Text;
和
string lstnme=((TextBox)row.Cells[2].Controls[0]).Text;
}
最佳答案
没有区别,但我建议您在分配Text值之前检查控件是否为null
string lstnme = string.Empty;
var control = ((TextBox)row.Cells[2].FindControl("txtLstNme"));
if ( control != null )
{
lstnme = control.Text
}