当前位置: 动力学知识库 > 问答 > 编程问答 >

asp.net - Recursive Function for Server Control Collection of subitems

问题描述:

I have control that has a list of items with subitems. I need to have a recursive function that collects the sub items.

e.g How do I collect and iterate this collection that has sub items?

is an ArrayList MenuItems the appropriate Type to use?

<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>

Here is the control:

 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);

}

}

}

分享给朋友:
您可能感兴趣的文章:
随机阅读: