2012-01-12 4 views
1

웹 응용 프로그램에서 RowDataBound 이벤트에서 눈금 컨트롤을 찾으려고합니다. 하지만 객체의 인스턴스에 객체 참조를주는 것은 내 코드입니다.Gridview에서 컨트롤 찾기? Asp.net에서?

 protected void mygrid_RowDataBound(object sender, GridViewRowEventArgs e) 
      { 

       string empid = "";   

       empid = ((Label)e.Row .FindControl("lblname")).Text; 
      } 

컨트롤을 찾으려면 클릭하십시오. 감사합니다. 단지처럼 데이터 행에 대한

+0

[2를이'라벨 lblprop_img_id = (라벨) e.Row.Cells를 시도 제어를 얻을 수

 string empid = ""; if (e.Row.RowType == DataControlRowType.DataRow) { empid = ((Label)e.Row.FindControl("lblname")).Text; } 

을 배치해야 ] .FindControl ("lblprop_img_id"); ' – Murtaza

답변

1

그래, 내가 대답을 얻었다, 나는 그때 우리가

1

찾기 제어 : 통제라는 lblname는 현재 행을 찾을 수 없습니다 때문에

protected void mygrid_RowDataBound(object sender, GridViewRowEventArgs e) 
{ 

    if (e.Row.RowType == DataControlRowType.DataRow) 
     { 
      string empid = "";   

      empid = ((Label)e.Row .FindControl("lblname")).Text; 
     } 
} 
+0

감사합니다, pankaj, 나는 그것을 얻었습니다. 나는 대답을 게시했습니다. 답장을 보내 주셔서 감사합니다. –

1

은 "개체의 인스턴스에 대한 개체 참조"오류 아마입니다.

헤더 행에서 컨트롤을 검색하지 않도록 e.Row.RowType = DataControlRowType.DataRow 행의 유형을 확인해야 할 수 있습니다.

1
Label lbl = (Label)e.Row.Cells[2].FindControl("lblCreatedBy"); 
      lbl.Text = "ABC";