/// <summary>
        /// Renders the empty message row
        /// </summary>
        /// <param name="writer"></param>
        public void RenderEmptyMessage(HtmlTextWriter writer)
        {
            // get the last row and render it
            OSDataGridTable child = (OSDataGridTable)Controls[0];

            child.Rows[child.Rows.Count - 1].RenderControl(writer);
        }
        /// <summary>
        /// Renders the last row in the datagrid
        /// </summary>
        /// <param name="writer"></param>
        public void RenderLastRow(HtmlTextWriter writer)
        {
            // get the last row before the footer and pager and render it
            OSDataGridTable child = (OSDataGridTable)Controls[0];

            child.Rows[child.Rows.Count - 3].RenderControl(writer);
        }
        /// <summary>
        /// Renders a specific row of the datagrid
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="rowIndex"></param>
        public void RenderRow(HtmlTextWriter writer, int dataItemIndex)
        {
            // find the control index for the data item index
            int             controlIndex = GetItemControlIndex(dataItemIndex);
            OSDataGridTable child        = (OSDataGridTable)Controls[0];

            child.Rows[controlIndex].RenderControl(writer);
        }
        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();
        }
Esempio n. 5
0
        public static OSDataGridTable FromTable(OSDataGrid parent, System.Web.UI.WebControls.Table table, ArrayList rowIds, ArrayList itemIndexes)
        {
            OSDataGridTable osTable = new OSDataGridTable(parent.ClientID);

            // copy everything from table
            // Properties
            osTable.BackImageUrl    = table.BackImageUrl;
            osTable.Caption         = table.Caption;
            osTable.CaptionAlign    = table.CaptionAlign;
            osTable.CellPadding     = table.CellPadding;
            osTable.CellSpacing     = table.CellSpacing;
            osTable.GridLines       = table.GridLines;
            osTable.HorizontalAlign = table.HorizontalAlign;

            // Rows
            TableRow[] tableRows = new TableRow[table.Rows.Count];
            table.Rows.CopyTo(tableRows, 0);

            int i = 0;

            foreach (OSDataGridItem row in tableRows)
            {
                try {
                    // restore the original id of this row, if set
                    if (rowIds != null)
                    {
                        row.ID = OSDataGridItem.FormatId((int)rowIds[i], parent.EnableLegacyRendering);
                    }
                    else
                    {
                        row.ID = OSDataGridItem.FormatId(i + 1, parent.EnableLegacyRendering);
                    }

                    // set the item index, if set
                    if (itemIndexes != null)
                    {
                        row.SetItemIndex((int)itemIndexes[i]);
                    }
                } catch (ArgumentOutOfRangeException) {
                    throw new HEMessageException(MR.GetMessage(MessageId.AjaxListModified, "Table Records", parent.ClientID));
                }

                osTable.Rows.Add(row);
                i++;
            }

            return(osTable);
        }
        public void RefreshItem(int dataItemIndex)
        {
            // set the datasource position
            IOSList rl = DataSource;

            rl.SetPosition(dataItemIndex);
            SelectedIndex = dataItemIndex;

            // databind the correspondent datagriditem
            int             controlIndex = GetItemControlIndex(dataItemIndex);
            OSDataGridTable child        = (OSDataGridTable)Controls[0];
            OSDataGridItem  item         = (OSDataGridItem)child.Rows[controlIndex];

            // initialize item
            item.DataItem = rl.Current;
            InitializeItem(item, false);
            item.DataBind();
        }
        /// <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;
        }
        protected override void CreateControlHierarchy(bool useDataSource)
        {
            SelectedIndex = -1;

            if (useDataSource)
            {
                DataSource.StartIteration();
                if (!DataSource.Empty)
                {
                    DataSource.Advance(StartIndex);
                }
            }

            base.CreateControlHierarchy(useDataSource);

            if (useDataSource)
            {
                DataSource.EndIteration();
            }

            // replace with created Table control with OSTable, for controlling viewstate growth and for restoring previous row ids
            ArrayList rowIds      = GetViewStateRowIds();
            ArrayList itemIndexes = GetViewStateItemIndexes();

            System.Web.UI.WebControls.Table table = (System.Web.UI.WebControls.Table) this.Controls[0];

            // determine if row ids are being generated in legacy mode or not
            string firstClientId  = table.Rows[0].ClientID;
            int    separatorIndex = firstClientId.IndexOf("_");

            if (separatorIndex >= 0)
            {
                _enableLegacyRendering = firstClientId.Substring(separatorIndex).StartsWith("__ctl");
            }

            OSDataGridTable osTable = OSDataGridTable.FromTable(this, table, rowIds, itemIndexes);

            this.Controls.Clear();
            this.Controls.Add(osTable);
        }
        /// <summary>
        /// Adds the empty row item if necessary
        /// </summary>
        private void AddEmptyRow()
        {
            bool any = false;

            foreach (OSDataGridItem item in this.Controls[0].Controls)
            {
                if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
                {
                    any = true;
                    break;
                }
            }
            if (!any)
            {
                _isEmpty = true;
                // add empty row...
                OSDataGridItem dataGridItem = new OSDataGridItem(0, 0, ListItemType.Item);

                // mark this as empty message item
                dataGridItem.IsEmptyMessageItem = true;
                OSDataGridTableCell tableCell = new OSDataGridTableCell();
                tableCell.ColumnSpan = TotalColumnSpan;
                tableCell.CssClass   = OddLineStyle;

                tableCell.Text = EmptyMessage;
                dataGridItem.Cells.Add(tableCell);

                OSDataGridTable child = (OSDataGridTable)Controls[0];
                child.Rows.Add(dataGridItem);
                // Making the id item ok based on the number of elements
                dataGridItem.ID = OSDataGridItem.FormatId(child.Rows.Count, EnableLegacyRendering);
            }
            else
            {
                _isEmpty = false;
            }
        }
        /// <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;
        }