Monday, August 02, 2010

How to create List Item Collection Property in asp.net

Code:
[ParseChildren(true)]
public partial class Rainbow : UserControl
{
    [DesignerSerializationVisibilityDesignerSerializationVisibility.Visible)]
    [PersistenceMode(PersistenceMode.InnerProperty)]
    public List<RainbowColor> Colors { getset; }
 
    protected override void AddParsedSubObject(object obj)
    {
        if (obj.GetType() == typeof(RainbowColor))
            this.Colors.Add((RainbowColor)obj);
        else
            base.AddParsedSubObject(obj);
    }
}
 
public class RainbowColor : WebControlINamingContainer
{
    public RainbowColorType Color { getset; }
}
 
public enum RainbowColorType { Red, Blue, Yellow, Green, Indigo, Orange, Violet }

Markup:

<asp:Rainbow runat="server" ID="rbwCurrent">
    <Colors>
        <asp:RainbowColor Color="Blue" />
        <asp:RainbowColor Color="Red" />
    </Colors>
</asp:Rainbow>

No comments:

Azure Storage Account Types

Defferent Types of Blobs Block blobs store text and binary data. Block blobs are made up of blocks of data that can be managed individually...