2014-12-22 3 views
1

안녕하세요, 업데이트를 클릭하고 OnRowUpdate 이벤트를 트리거 한 후 오류가 발생했습니다. usercontrol에서 텍스트 상자의 값을 가져 오는 올바른 형식은 무엇입니까?UserControl OnRowUpdate의 텍스트 상자 FindControl

에러 55 'System.Web.UI.UserControl' 'PLANID'의 정의없이 연장 방법 "PLANID '유형의 첫번째 인수 접수를 포함하지 않는'System.Web.UI.UserControl ' 볼 수 있습니다 (당신은 지시문 또는 어셈블리 참조를 사용하여 누락

당신은.주의 클라이언트 ID를 사용하여 컨트롤에 액세스해야
protected void grd_Plan_RowUpdating(object sender, GridViewUpdateEventArgs e) 
     { 

      string PlanCode =((UserControl)Grid_Plan.Rows[e.RowIndex].FindControl("ucPlanID")).PlanID; 
     } 

//usercontrol code behind 

public string PlanID 
     { 
      get 
      { 
       return txtPlanID.Text; 
      } 
      set 
      { 
       txtPlanID.Text = value; 
      } 
     } 

답변

1

이 시도 : -

UserControl ucPlanID = (UserControl)Grid_Plan.Rows[e.RowIndex].FindControl("ucPlanID"); 
if (ucPlanID != null) 
{ 
    string PlanCode = ((TextBox)ucPlanID.FindControl("PlanID")).Text; 
} 

고려가 PlanID 당신의 텍스트 상자의 ID입니다.

+1

멋진 작품입니다. 감사합니다. –

0

새로운 닷넷 프레임 워크 버전은 클라이언트 ID 모드를 설정할 수있는 경우에 그 정적이게 당신의 cont에 부여한 클라이언트 ID와 이름을 보장합니다. 롤은 동일합니다.