1

サブアイテムを持つアイテムのリストを持つコントロールがあります。サブアイテムを収集する再帰関数が必要です。
例: サブアイテムを持つこのコレクションを収集して反復するにはどうすればよいですか?
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);
        }
    }
}
4

0 に答える 0