2014-01-30 3 views
1

ASP.NET에서 프로그래밍 방식으로 DynamicControl 모드를 변경하고 싶습니다. 이미 두 가지 방법을 시도했지만 두 번 모두 실패했습니다. 먼저 코드에서 코드를 수행하려고 시도했습니다. DynamicControls 모드가 "편집"으로 설정됩니다. 페이지로드시 컨트롤을 반복하고이 모드를 변경하려고 시도했습니다.ASP.NET : 프로그래밍 방식으로 DynamicControl 모드를 변경하는 방법

((DynamicControl)c).Mode = DataBoundControlMode.ReadOnly; 

이 결과는 없습니다.

두 번째 방법에서는 aspx 페이지에서 인라인 표현식을 사용했습니다.

Mode= "<%#getDynamicControlMode(MPFormView) %>" 

코드에서 사용되는 기능은 뒤에서이 메소드는 실패

public DataBoundControlMode getDynamicControlMode(FormView fv) 
    { 
     if (fv.CurrentMode == FormViewMode.ReadOnly) 
      return DataBoundControlMode.ReadOnly; 
     else if (fv.CurrentMode == FormViewMode.Edit) 
      return DataBoundControlMode.Edit; 
     else 
      return DataBoundControlMode.Insert; 
    } 

되고, 제어없이 FormViewMode의 읽기 전용 모드에 머물렀다. FormView에서 하나의 템플릿 만 사용하기 때문에이 programaticall을 수행하려고합니다. 감사합니다.

답변

0

마지막으로 나는 아래쪽 컨트롤을 얻으려면 DynamicControl을 파헤쳐야한다는 것을 알았습니다.

    foreach (Control ct in cont.Controls)//cont is the DynamicControl 
         { 
          foreach (Control ci in ct.Controls) 
          { 
           if (ci is CheckBox) 
            ((CheckBox)ci).Enabled = enable; 
           if (ci is TextBox) 
            ((TextBox)ci).Enabled = enable; 
          } 
         } 

이 방법은 내가 사용할 컨트롤을 가지고 있지만 그것뿐만 아니라 나에게 맞는 : 그래서 나는 다음과 같은 코드를 사용하여 내 문제를 해결했다.