服务器控制子项集合的递归函数
我有一个包含子项目的项目列表的控件。我需要一个递归函数来收集子项目。
例如,我如何收集和迭代这个包含子项目的集合?
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);
}
}
}
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);
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论