/// <summary>
        /// Stores the current row ids to the viewstate
        /// </summary>
        public void StoreViewStateRowIdsandItemIndexes()
        {
            // store the current ids of every child rows...
            OSDataGridTable child       = Controls[0] as OSDataGridTable;
            ArrayList       rowIds      = new ArrayList(child.Rows.Count);
            ArrayList       itemIndexes = new ArrayList(child.Rows.Count);
            int             i           = 1;

            foreach (OSDataGridItem item in child.Rows)
            {
                if (item.ID == null)
                {
                    item.ID = OSDataGridItem.FormatId(i, EnableLegacyRendering);
                }
                rowIds.Add(OSDataGridItem.GetIntegerId(item.ID, EnableLegacyRendering));
                itemIndexes.Add(item.ItemIndex);
                i++;
            }
            ViewState["RowIds"]  = rowIds;
            ViewState["RowIdxs"] = itemIndexes;
        }
        /// <summary>
        /// Inserts an item to the datagrid
        /// </summary>
        /// <param name="param name="dataItemIndex"></param>
        /// <param name="dataItem"></param>
        public void InsertItem(int dataItemIndex, object dataItem)
        {
            // check if the current page is full
            IOSList rl = DataSource;

            // update the datasource
            rl.Insert(dataItem, dataItemIndex);

            // set the record list position and databind the item
            rl.SetPosition(dataItemIndex);

            // create an item at the end of the list
            OSDataGridItem        item = (OSDataGridItem)CreateItem(dataItemIndex, dataItemIndex, ListItemType.Item);
            DataGridItemEventArgs e    = new DataGridItemEventArgs(item);

            // initialize item
            item.DataItem = dataItem;
            InitializeItem(item, true);
            this.OnItemCreated(e);

            OSDataGridTable child = (OSDataGridTable)Controls[0];

            // remove any empty message row...
            if (((OSDataGridItem)child.Rows[child.Rows.Count - 1]).IsEmptyMessageItem)
            {
                child.Rows.RemoveAt(child.Rows.Count - 1);
            }

            // insert the item before the footer and pager items
            int footerIndex = child.Rows.Count - 2;

            int footerId;

            if (child.Rows[footerIndex].ID != null)
            {
                footerId = OSDataGridItem.GetIntegerId(child.Rows[footerIndex].ID, EnableLegacyRendering);
            }
            else
            {
                footerId = footerIndex + 1;
            }

            child.Rows.AddAt(footerIndex, item);

            // generate a new item id for this control
            int id = footerId;

            item.ID = OSDataGridItem.FormatId(id, EnableLegacyRendering);

            // increase the footer and pager items, so that no repateated ids exist in the page
            child.Rows[child.Rows.Count - 2].ID = OSDataGridItem.FormatId(id + 1, EnableLegacyRendering);
            child.Rows[child.Rows.Count - 1].ID = OSDataGridItem.FormatId(id + 2, EnableLegacyRendering);

            ViewState["_!ItemCount"] = rl.Length;
            _isEmpty = false;

            // increase higher item indexes in the data grid
            foreach (OSDataGridItem otherItem in child.Rows)
            {
                if (otherItem.ItemIndex >= dataItemIndex && otherItem != item)
                {
                    otherItem.SetItemIndex(otherItem.ItemIndex + 1);
                }
            }

            // update row ids in the viewstate
            StoreViewStateRowIdsandItemIndexes();

            SelectedIndex = dataItemIndex;

            item.DataBind();
            this.OnItemDataBound(e);

            item.DataItem = null;
        }