从ASP.Net的递归函数返回Arraylist
请参阅随附的屏幕截图。我有一个复选框数组和一个返回ASP.Net页面的帖子按钮。我编写了如下函数,以确定在按钮单击事件中选中了哪些复选框:以下代码是从ASP.Net调用的业务组件的一部分。请让我知道如何将actionArray返回到ASP.Net页面中调用functon从ASP.Net的递归函数返回Arraylist,asp.net,Asp.net,请参阅随附的屏幕截图。我有一个复选框数组和一个返回ASP.Net页面的帖子按钮。我编写了如下函数,以确定在按钮单击事件中选中了哪些复选框:以下代码是从ASP.Net调用的业务组件的一部分。请让我知道如何将actionArray返回到ASP.Net页面中调用functon public void checkBoxValidation(Control parent, string strKey) { XmlDocument getCyleXML = new XmlDo
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);
}
}
}
代码应如下所示:
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;
}
调用函数在哪里?你为什么不能把名单还给我?不要使用XmlDocument和ArrayList,而是使用XDocument和List。非常感谢您的帮助。