.ASPX 上的自定义用户控件和友好的属性项集合(类似于 ListBox 和 ListItems,但带有 L​​ist<Class>) [英] Custom User Control and Friendly Property Item Collection (Like ListBox and ListItems, but with List&lt;Class&gt;) on .ASPX

查看:11
本文介绍了.ASPX 上的自定义用户控件和友好的属性项集合(类似于 ListBox 和 ListItems,但带有 L​​ist<Class>)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直想知道如何为用户控件创建一个公共属性,该属性类似于 .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,但带有 L​​ist<Class>)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆