public void RemoveItem(int itemIndex)
        {
            // clear selected item, if deleting the current selected index
            if (SelectedIndex == itemIndex)
            {
                SelectedIndex = -1;
            }

            // remove the correspondent data item from the controls
            OSDataGridTable child = (OSDataGridTable)Controls[0];
            // find the row corresponding to this index
            int rowIndexToRemove = -1;

            for (int i = 0; i < child.Rows.Count; i++)
            {
                OSDataGridItem item   = (OSDataGridItem)child.Rows[i];
                bool           isItem = item.ItemType == ListItemType.AlternatingItem || item.ItemType == ListItemType.Item;
                if (isItem && item.ItemIndex == itemIndex)
                {
                    rowIndexToRemove = i;
                    break;
                }
            }

            IOSList rl = DataSource;

            if (rowIndexToRemove == -1 || itemIndex >= rl.Length)
            {
                throw new ArgumentException("Index of out range");
            }

            child.Rows.RemoveAt(rowIndexToRemove);

            // update the datasource
            rl.Remove(itemIndex);

            // update item count
            ViewState["_!ItemCount"] = rl.Length;

            // decrease higher item indexes in the data grid
            foreach (OSDataGridItem otherItem in child.Rows)
            {
                if (otherItem.ItemIndex > itemIndex)
                {
                    otherItem.SetItemIndex(otherItem.ItemIndex - 1);
                }
            }

            // add empty row if necessary
            AddEmptyRow();

            // update row ids in the viewstate
            StoreViewStateRowIdsandItemIndexes();
        }
        public void RemoveItem(int itemIndex)
        {
            // clear selected item, if deleting the current selected index
            if (SelectedIndex == itemIndex)
            {
                SelectedIndex = -1;
            }

            // find the Repeater Item for this itemItem
            int rowIndexToRemove = -1;

            for (int i = 0; i < Controls.Count; i += 2)
            {
                IIteratorItem item = (IIteratorItem)Controls[i];
                if (item.ItemIndex == itemIndex)
                {
                    rowIndexToRemove = i;
                    break;
                }
            }

            IOSList rl = DataSource;

            if (rowIndexToRemove == -1 || itemIndex >= rl.Length)
            {
                throw new ArgumentException("Index of out range");
            }

            // remove the repeater item
            Controls.RemoveAt(rowIndexToRemove);
            // remove also the invisible item, now at the same position
            Controls.RemoveAt(rowIndexToRemove);

            // update the datasource
            rl.Remove(itemIndex);

            // update item count
            ViewStateAttributes.SetInViewState("NumItems", ItemCount, null);
            // set the empty property
            _isEmpty = (rl.Length == 0);

            // decrease higher item indexes in the iterator
            foreach (IIteratorItem otherItem in Controls)
            {
                if (otherItem.ItemIndex > itemIndex)
                {
                    otherItem.ItemIndex--;
                }
            }

            // update item ids and indexes in the viewstate
            StoreViewStateItemIdsandIndexes();
        }