服务器控件的递归函数子集的集合

时间:2011-04-15 11:57:36

标签: asp.net custom-server-controls servercontrols

我有一个包含子项的项目列表的控件。我需要一个收集子项的递归函数 例如,我如何收集和迭代这个包含子项的集合?
是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);
        }
    }
}

0 个答案:

没有答案