我很长时间以来一直想知道如何为用户控件创建一个公共属性,该属性类似于 .NET 本机项的集合属性(例如,ListBox 和 ListItems):
<asp:ListBox blablabla>
<asp:ListItem></asp:ListItem> <- Inline item collection...
</asp:ListBox>
我一直在网上检查但没有成功。我认为它一定是我需要添加到属性中的任何类型的属性,或者应该需要由用户控件继承的接口,但对此没有任何线索,并且已经考虑了很长时间。
我必须在自定义用户控件上使用它,但 Visual Studio 没有将其识别为有效的项目集合。
假设我们有这个 userControl:
public partial class userControls_Blablabla : System.Web.UI.UserControl
{
public List<configItem> ConfigItem {get; set; }
blablabla...rest logic here...
}
public class configItem {
public string Name {get; set;}
public string Url {get; set;}
public string Color {get; set;}
blablabla...rest logic here...
}
应该如何做,才能在 Visual Studio 的 .ASPX 编辑器上执行类似的操作,并被 Intellisense 识别?
<User_Control:userControls_Blablabla ID="blablabla" ...blablabla....>
<ConfigItem Name="1" Url="...." Color="..." />
<ConfigItem Name="2" Url="...." Color="..." />
<ConfigItem Name="3" Url="...." Color="..." />
</User_Control:userControls_Blablabla>
抱歉我的英语不好,我知道它不是很好。
提前致谢!
您可以在控件类中放置您的类型列表,并使用持久模式属性进行装饰。
[PersistenceMode(PersistenceMode.InnerProperty)]
public List<configItem> ConfigItem { get; set; }
一个更好的例子:
http://am-blog.no-ip.org/BlogEngine/post/2010/04/13/ASP-NET-Custom-Control-with-PersistenceModeInnerProperty-using-Server-Controls.aspx
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)