Custom User Control and Friendly Property Item Collection (Like ListBox and ListItems, but with Listlt;Classgt;) on .ASPX(.ASPX 上的自定义用户控件和友好的属性项集合(类似于 ListBox 和 ListItems,但带有 ListClass))
问题描述
我一直想知道如何为用户控件创建一个公共属性,该属性类似于 .NET 原生项的集合属性(例如,ListBox 和 ListItems):
I have been wondering a long time how to do a public property for a User Control that work's like .NET native Item's collection Property (for Example, ListBox and ListItems):
<asp:ListBox blablabla>
<asp:ListItem></asp:ListItem> <- Inline item collection...
</asp:ListBox>
我一直在网上查,但没有任何成功.我认为它必须是我需要添加到属性中的任何类型的属性,或者应该需要由用户控件继承的接口,但没有任何线索,并且已经考虑了很长时间.
I have been checking around the web but without any sucess. I think it must be any type of attribute that i need to add to the property, OR interface that should need to be inherited by the user control, but no clue about it, and have been thinking about it long time.
我必须在自定义用户控件上使用它,但 Visual Studio 没有将它识别为有效的项目集合.
I have got to work it on a custom user control, but Visual Studio didn't recognised it as a valid item collection.
假设我们有这个 userControl:
Let's say that we have this 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识别?
How should be done, to be able to do something like that on the .ASPX editor of Visual Studio, and it get recognised by 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>
对不起我的英语,我知道它不是很好.
Sorry for my english, i know it's not very good.
提前致谢!
推荐答案
你需要用足够的信息来装饰控件和它的属性,以便设计人员在设计时可以了解细节.你检查过这个链接了吗?
You need to decorate the control and it's properties with sufficient information that the designer can pick up on details at design time. Have you checked this link?
这篇关于.ASPX 上的自定义用户控件和友好的属性项集合(类似于 ListBox 和 ListItems,但带有 List<Class>)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:.ASPX 上的自定义用户控件和友好的属性项集合(类似于 ListBox 和 ListItems,但带有 List<Class>)
基础教程推荐
- 从 C# 控制相机设备 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
- 将数据集转换为列表 2022-01-01
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
- 如果条件可以为空 2022-01-01
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- 获取C#保存对话框的文件路径 2022-01-01
