/// <summary>
 /// Gets the safe wrapped item.
 /// </summary>
 /// <param name="item">The item.</param>
 /// <returns></returns>
 private ListItem GetSafeWrappedItem(ExtendedListItem item)
 {
     return (null != item) ? item._listItem : null;
 }
 /// <summary>
 /// Inserts the specified index.
 /// </summary>
 /// <param name="index">The index.</param>
 /// <param name="item">The item.</param>
 public void Insert(int index, ExtendedListItem item)
 {
     this._wrappedCollection.Insert(index, this.GetSafeWrappedItem(item));
 }
 /// <summary>
 /// Removes the specified item.
 /// </summary>
 /// <param name="item">The item.</param>
 public void Remove(ExtendedListItem item)
 {
     this._wrappedCollection.Remove(this.GetSafeWrappedItem(item));
 }
 /// <summary>
 /// Determines whether [contains] [the specified item].
 /// </summary>
 /// <param name="item">The item.</param>
 /// <returns>
 /// 	<c>true</c> if [contains] [the specified item]; otherwise, <c>false</c>.
 /// </returns>
 public bool Contains(ExtendedListItem item)
 {
     return this._wrappedCollection.Contains(this.GetSafeWrappedItem(item));
 }
 /// <summary>
 /// Indexes the of.
 /// </summary>
 /// <param name="item">The item.</param>
 /// <returns></returns>
 public int IndexOf(ExtendedListItem item)
 {
     return this._wrappedCollection.IndexOf(this.GetSafeWrappedItem(item));
 }
 /// <summary>
 /// Adds the range.
 /// </summary>
 /// <param name="items">The items.</param>
 public void AddRange(ExtendedListItem[] items)
 {
     if (null != items)
     {
         ListItem[] listItems = new ListItem[items.Length];
         for (int i = 0; i < items.Length; i++)
         {
             listItems[i] = items[i]._listItem;
         }
         this._wrappedCollection.AddRange(listItems);
     }
 }
 /// <summary>
 /// Adds the specified item.
 /// </summary>
 /// <param name="item">The item.</param>
 public void Add(ExtendedListItem item)
 {
     this._wrappedCollection.Add(this.GetSafeWrappedItem(item));
 }
        /// <summary>
        /// Writes the option group.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="writer">The writer.</param>
        private void WriteOptionGroup(ExtendedListItem item, HtmlTextWriter writer)
        {
            if (_optGroupStarted)
                writer.WriteEndTag("optgroup");

            writer.WriteBeginTag("optgroup");
            writer.WriteAttribute("label", item.GroupingText);
            if (!item.Enabled)
                writer.WriteAttribute("disabled", "disabled");
            if (!string.IsNullOrEmpty(item.GroupCssClass))
                writer.WriteAttribute("class", item.GroupCssClass);
            writer.Write('>');
            // writer.WriteLine();
            _optGroupStarted = true;
        }
        /// <summary>
        /// Writes the option.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="writer">The writer.</param>
        private void WriteOption(ExtendedListItem item, HtmlTextWriter writer)
        {
            writer.WriteBeginTag("option");
            if (item.Selected)
            {
                writer.WriteAttribute("selected", "selected");
            }

            if (!string.IsNullOrEmpty(item.CssClass))
                writer.WriteAttribute("class", item.CssClass);

            writer.WriteAttribute("value", item.Value, true);

            //raul: we're in trouble here, it renders what it shouldn't....[GroupType, CssClass, etc]
            //if (item.Attributes.Count > 0)
            //{
            //    item.Attributes.Render(writer);
            //}

            if (this.Page != null)
            {
                this.Page.ClientScript.RegisterForEventValidation(this.UniqueID, item.Value);
            }

            writer.Write('>');
            HttpUtility.HtmlEncode(item.Text, writer);
            writer.WriteEndTag("option");
            writer.WriteLine();
        }
        /// <summary>
        /// Writes the option.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="writer">The writer.</param>
        private void WriteOption(ExtendedListItem item, HtmlTextWriter writer)
        {
            writer.WriteBeginTag("option");
            if (item.Selected)
            {
                if (_selected)
                {
                    this.VerifyMultiSelect();
                }
                _selected = true;
                writer.WriteAttribute("selected", "selected");
            }

            if (!string.IsNullOrEmpty(item.CssClass))
                writer.WriteAttribute("class", item.CssClass);

            writer.WriteAttribute("value", item.Value, true);

            if (item.Attributes.Count > 0)
            {
                StateBag bag = new StateBag();
                foreach (string attrKey in item.Attributes.Keys)
                {
                    if (attrKey.IndexOf(ExtendedListItem._attrPrefix) == -1)
                        bag.Add(attrKey, item.Attributes[attrKey]);
                }

                System.Web.UI.AttributeCollection coll = new System.Web.UI.AttributeCollection(bag);

                coll.Render(writer);
            }

            if (this.Page != null)
            {
                this.Page.ClientScript.RegisterForEventValidation(this.UniqueID, item.Value);
            }

            writer.Write('>');
            HttpUtility.HtmlEncode(item.Text, writer);
            writer.WriteEndTag("option");
            writer.WriteLine();
        }