2011-12-21 2 views
0

나는 RealWorld.Grids.FrozenGridView을 가지고 있으며 그리드의 여러 확인란 (마지막 열에 있음)을 선택한 후 C# 파일의 행에 액세스하여 선택한 행, 그리드에서 일부 작업을 실행하려고합니다 null로 나오고 그리드의 이름을 기반으로 페이지에서 find를하려고 할 때 결과는 null입니다. 나는 또한 시도업데이트 패널의 FrozenGridView에 액세스 할 수 없습니다.

UpdatePanel up1 = new UpdatePanel(); 
    up1.ID = "updatepanelID"; 
    Label gn = (Label)up1.FindControl("labelname"); 

:

label lbl = (Label)this.Page.FindControl("updatepanelid").FindControl("labelname") as Label; 

gridname = (RealWorld.Grids.FrozenGridView)this.FindControl("gridname") as RealWorld.Grids.FrozenGridView; 

그리드는 그래서 같은 찾기 컨트롤의 업데이트 패널을 포함 그리드에 액세스 할 updatepanel에 위치 button_click 이벤트에서 발생해야합니다.

이 유형의 문제에 경험이있는 사람이 있습니까?

도움을 주시면 감사하겠습니다.

답변

0

FindControl이 예상대로 작동하지 않을 수 있습니다. 이 재귀 함수를 사용하고 위로 올라온 코드 줄을 사용하십시오.

public static Control FindControlRecursive(Control ctlRoot, string sControlId) 
    { 
     // if this control is the one we are looking for, break from the recursion  
     // and return the control.  
     if (ctlRoot.ID == sControlId) 
     { 
      return ctlRoot; 
     } 
     // loop the child controls of this parent control and call recursively.  
     foreach (Control ctl in ctlRoot.Controls) 
     { 
      Control ctlFound = FindControlRecursive(ctl, sControlId); 
      // if we found the control, return it.   
      if (ctlFound != null) 
      { 
       return ctlFound; 
      } 
     }// we never found the control so just return null.  
     return null; 
    } 

전화는 다음과 같습니다.

var ridname = (RealWorld.Grids.FrozenGridView)FindControl(this, "gridname") as RealWorld.Grids.FrozenGridView; 
+0

감사합니다! 그러나 그리드의 행은 여전히 ​​액세스 할 수 없으며 행에 대해 0을 보여줍니다. 왜 그런 일이 발생할 수 있는지에 대한 조언이 있습니까? – Sue

관련 문제