我有一个包含子项的项目列表的控件。我需要一个收集子项的递归函数
例如,我如何收集和迭代这个包含子项的集合?
是ArrayList MenuItems要使用的相应类型吗?
<myControl:Menu id="MyControl" runat="server">
<mycontrol:MenuItem Text="Hellow World">
<mycontrol:MenuItem Text="Hellow World">
<mycontrol:MenuItem Text="Hellow World" />
</myControl:menuItem>
</myControl:menuItem>
</myControl:Menu>
以下是控件:
public class QuickControl: WebControl
{
private ArrayList MenuItems;
[
Category("Behavior"),
Description("The contacts collection"),
DesignerSerializationVisibility(
DesignerSerializationVisibility.Content),
Editor(typeof(MenuCollectionEditor), typeof(UITypeEditor)),
PersistenceMode(PersistenceMode.InnerDefaultProperty)
]
public ArrayList MenuItems
{
get
{
if (MenuList == null)
{
MenuList = new ArrayList();
}
return MenuList;
}
}
// The contacts are rendered in an HTML table.
protected override void RenderContents(
HtmlTextWriter writer)
{
Table t = CreateContactsTable();
if (t != null)
{
t.RenderControl(writer);
}
}
}