如何创建具有集合的控件
好吧,让我说得更具体一些。我知道如何创建具有集合属性的控件,但我从未编写过与其关联的标记的控件。
我想知道的是,给定这样定义的控件...
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要应用 DesignerSerializationVisibilityAttribute 以及
这就是它的样子 -
请参阅 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 -
See MSDN: Web Control Collection Property Example for a detailed example.
您可能正在寻找模板化控件 http://msdn.microsoft.com/en-我们/library/aa478964.aspx
You are probably looking for Templated controls http://msdn.microsoft.com/en-us/library/aa478964.aspx