如何创建具有集合的控件

发布于 2024-11-07 01:47:33 字数 473 浏览 0 评论 0原文

好吧,让我说得更具体一些。我知道如何创建具有集合属性的控件,但我从未编写过与其关联的标记的控件。

我想知道的是,给定这样定义的控件...

public class MyControl 
{
    public List<MySubItems> Items {get; set;}
}

我必须做什么才能创建标记,像这样...

<MyStuff:MyControl runat="server" ID="MyControl1">
  <Items>
    <MySubItem ... />
    <MySubItem ... />
  </Items>
</MyStuff:MyControl>

抱歉,如果这看起来有点棘手的问题,但我从来没有以前做过这个。

-- 斯图尔特

OK, let me be more specific. I know how to create a control with a collection property, but what I've never done is written one that has markup associated with it.

What I want to know is, given an control defined like this ...

public class MyControl 
{
    public List<MySubItems> Items {get; set;}
}

What do I have to do to be able to create markup, like this...

<MyStuff:MyControl runat="server" ID="MyControl1">
  <Items>
    <MySubItem ... />
    <MySubItem ... />
  </Items>
</MyStuff:MyControl>

Apologies if this seems a bit of a noddy question, but I've never done this before.

--
Stuart

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

り繁华旳梦境 2024-11-14 01:47:33

您需要应用 DesignerSerializationVisibilityAttribute 以及

这就是它的样子 -

public class MyControl:WebControl
{
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
    PersistenceMode(PersistenceMode.InnerDefaultProperty)]
    public List<MySubItems> Items {get; set;}
}

请参阅 MSDN: Web 控件集合属性示例查看详细示例。

You'll need to apply the DesignerSerializationVisibilityAttribute along with PersistenceModeAttribute on your property. Assuming it's a ASP.NET control.

This is what it would look like -

public class MyControl:WebControl
{
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
    PersistenceMode(PersistenceMode.InnerDefaultProperty)]
    public List<MySubItems> Items {get; set;}
}

See MSDN: Web Control Collection Property Example for a detailed example.

却一份温柔 2024-11-14 01:47:33

You are probably looking for Templated controls http://msdn.microsoft.com/en-us/library/aa478964.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文