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:

iPhone Launch Screen Sizes

iPhone Portrait iOS 8 Retina HT 5.5 = 1242 X 2208 Retna HD 4.7 = 750 X 1134 iPhone Landscape iOS 8 Retina HD 5.5  2208 X 1242 iPho...