protected override void CreateChildControls()
        {
            this.Controls.Clear();

            // Build the header.
            if (this._header != null)
            {
                // We're just going to render it directly into the panel, since we
                //   don't want to "mess up" and formating the user might try and
                //   do here.
                this._header.InstantiateIn(this);
            }

            // Build the items.
            for (int i = 0; i < this.ItemCount; i++)
            {
                if (i > 0 && this._separator != null)
                {
                    this._separator.InstantiateIn(this);
                }

                PlusOneControlItem item = new PlusOneControlItem(this, this.AutoRemoveControl, null, this._items.Count);
                if (this._template != null)
                {
                    this._template.InstantiateIn(item);
                }

                item.AutoRemoveButtonClicked += new CommandEventHandler(this.item_OnAutoRemoveButtonClicked);

                this._items.Add(item);
                this.Controls.Add(item);
                this.OnItemCreated(new PlusOneItemEventArgs(item));
            }

            // Create an "extra" hidden control item.
            PlusOneControlItem itemHdn = new PlusOneControlItem(this, this.AutoRemoveControl, null, this._items.Count);

            itemHdn.Visible = false;
            if (this._template != null)
            {
                this._template.InstantiateIn(itemHdn);
            }
            this.Controls.Add(itemHdn);

            // Build the footer.
            if (this._footer != null)
            {
                // Same as the header, just render it exactly as specified.
                this._footer.InstantiateIn(this);
            }

            base.CreateChildControls();
        }
        public void RemoveItem(PlusOneControlItem item)
        {
            int idx = this.Controls.IndexOf(item);

            if (idx == -1)
            {
                throw new ArgumentOutOfRangeException("item", "Specified item was not found in the control.");
            }
            else
            {
                this.RemoveItemAt(idx);
            }
        }
        public void RemoveItemAt(int idx)
        {
            if (idx < 0 || idx > this._items.Count)
            {
                throw new ArgumentOutOfRangeException("idx");
            }

            PlusOneControlItem item = this._items[idx];

            this.Controls.Remove(item);
            this._items.RemoveAt(idx);
            this.ItemCount--;
            this.OnItemRemoved(new PlusOneItemEventArgs(item));
        }
        //***************************************************************************
        // Public Methods
        //
        public void CreateNew()
        {
            this.ItemCount++;

            for (int i = 0; i < this.Controls.Count; i++)
            {
                PlusOneControlItem ctrl = (this.Controls[i] as PlusOneControlItem);
                if (ctrl == null)
                {
                    continue;
                }

                // This works off the premise that we'll never have more than one
                //   PlusOneControlItem set to Visible=false.
                if (ctrl.Visible == false)
                {
                    ctrl.Visible = true;
                    if (this._separator != null)
                    {
                        // We don't want to create the seperator until we're actually
                        //   ready to show the "exta" item.  This *does* mean that
                        //   controls within the separator template cannot participate
                        //   in the view state.
                        Panel panSep = new Panel();
                        this._separator.InstantiateIn(panSep);
                        for (int t = 0; t < panSep.Controls.Count; t++)
                        {
                            this.Controls.AddAt(i + t, panSep.Controls[t]);
                        }
                    }
                    this._items.Add(ctrl);
                    this.OnItemAdded(new PlusOneItemEventArgs(ctrl));
                    break;
                }
            }
        }
 //***************************************************************************
 // Class Constructors
 //
 public PlusOneItemEventArgs(PlusOneControlItem item)
 {
     this.Item = item;
 }