DataRowView dv =(DataRowView)e.Row.DataItem;
string id=dv.Row["ProjectID"].ToString();

1、在行繫結(RowDataBound)事件中使用

//獲得行資料繫結中的TextBox1
    protected void gv1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        // 對於在RowDataBound中Find,可以用if (e.Row.RowType == DataControlRowType.DataRow)來限制Find的範圍,因為Find預設是在HeaderTemplate中找,如果不限定範圍,在HeaderTemplate中找不到,自然就返回null,然後就出錯了,DataControlRowType列舉中的DataRow確定是資料行.
        //if (e.Row.RowType == DataControlRowType.DataRow)
        //{
        //    TextBox tb = (TextBox)e.Row.FindControl("TextBox1");
        //    tb.Text = "databind";
        //}

//如果在DataGrid的頁首和頁尾:

//if (e.Row.RowType == DataControlRowType.Header)
        //{
        //    TextBox tbheader = (TextBox)e.Row.FindControl("txtHeader");
        //    tbheader.Text = "Head";
        //}
        ((TextBox)this.gv1.Controls[0].Controls[0].FindControl("txtHeader")).Text = "Head";

if (e.Row.RowType == DataControlRowType.Footer)
        {
            TextBox tbfooter = (TextBox)e.Row.FindControl("txtFooter");
            tbfooter.Text = "Footer";
        }
    }

2、在行命令(RowCommand)事件中使用

//行命令時間中找到TextBox1
    //如果使用GridView預設的模式,e.CommandArgument自動棒定為該行的Index,這時候只要指定gridview1.Rows[Convert.ToInt32(e.CommandArgument)].FindControl("xxx")就可以了,但是如果轉化為Template,e.CommandArgument並不會自動繫結任何值,需要手動繫結,可以在<ItemTemplate></ItemTemplate>手動寫CommandArgument="<%# ((GridViewRow) Container).RowIndex %>",把這個行的 Index繫結繫結到該e.CommandArgument就可以了.
    protected void gv1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.ToLower() == "change")
        {
            TextBox tb = (TextBox)this.gv1.Rows[Convert.ToInt32(e.CommandArgument)].FindControl("TextBox1");
            
            Response.Write(tb.Text);

  1. GridViewRow row = ((Button)e.CommandSource).Parent.Parent as GridViewRow;
  2. Label lblnumber = (Label)row.Cells[5].FindControl("lblNumber");

}
    }