2012-11-04 3 views
0

Checkbox Array 첨부 된 스크린 샷을 참조하십시오. 나는 체크 박스의 배열과 ASP.Net 페이지의 포스트에 대한 버튼을 가지고있다. 단추 클릭 이벤트에서 모든 확인란을 선택했는지 확인하기 위해 다음과 같은 함수를 작성했습니다. 다음 코드는 ASP.Net에서 호출되는 비즈니스 구성 요소의 일부입니다. ASP.Net 페이지에서 actionArray를 다시 호출 기능으로 되 돌리는 방법을 알려주십시오.ASP.Net의 재귀 함수에서 Arraylist 반환

public void checkBoxValidation(Control parent, string strKey) 
    { 
     XmlDocument getCyleXML = new XmlDocument(); 
     string strChkID="", strActionXPath = "",strAction=""; 
     ArrayList actionArray = new ArrayList(); 

     // Loop through all the controls on the page 
     foreach (Control c in parent.Controls) 
     { 
      // Check and see if it's a checkbox. 
      if ((c.GetType() == typeof(CheckBox))) 
      { 
       // Since its a checkbox, see if this is checked.  
       if (((CheckBox)(c)).Checked == true) 
       { 
        // Find the ID of the checkbox 
        strChkID = ((CheckBox)(c)).ID.ToString(); 
        getCyleXML = CycleXML(strKey); 
        strActionXPath = "/Actions/Action[checkbox='" + strChkID + "']/*[self::Name]"; 
        strAction = getCyleXML.SelectSingleNode(strActionXPath).ToString(); 
        actionArray.Add(strAction); 
       } 
      } 
      // Now we need to call itself (recursion) because all items (Panel, GroupBox, etc) is a container so we need to check 
      // all containers for any checkboxes. 
      if (c.HasControls()) 
      { 
       checkBoxValidation(c, strKey); 
      } 
     } 
    } 
+0

이 경우 호출하는 함수이다? 왜 그 목록을 반환 할 수 없습니까? XmlDocument와 ArrayList를 사용하지 말고 XDocument와 List 을 사용하십시오. –

답변

0

코드는 다음과 같아야합니다

public ArrayList checkBoxValidation(Control parent, string strKey, ArrayList actionArray) 
{ 
    XmlDocument getCyleXML = new XmlDocument(); 
    string strChkID="", strActionXPath = "",strAction=""; 
    if(actionArray == null) { actionArray = new ArrayList(); } 

    // Loop through all the controls on the page 
    foreach (Control c in parent.Controls) 
    { 
     // Check and see if it's a checkbox. 
     if ((c.GetType() == typeof(CheckBox))) 
     { 
      // Since its a checkbox, see if this is checked.  
      if (((CheckBox)(c)).Checked == true) 
      { 
       // Find the ID of the checkbox 
       strChkID = ((CheckBox)(c)).ID.ToString(); 
       getCyleXML = CycleXML(strKey); 
       strActionXPath = "/Actions/Action[checkbox='" + strChkID + "']/*self::Name]"; 
       strAction = getCyleXML.SelectSingleNode(strActionXPath).ToString(); 
       actionArray.Add(strAction); 
      } 
     } 
     // Now we need to call itself (recursion) because all items (Panel, GroupBox, etc) is a container so we need to check 
     // all containers for any checkboxes. 
     if (c.HasControls()) 
     { 
      checkBoxValidation(c, strKey, actionArray); 
     } 
    } 

    return actionArray; 
} 
+0

도움을 많이 주셔서 감사합니다. –