// override to create repeated items
        protected override void CreateChildControls()
        {
            if (!Visible)
            {
                return;
            }
            SelectedIndex = -1;

            object o = ViewStateAttributes.GetFromViewState("NumItems", null);

            if (o != null)
            {
                // get item ids and indexes for supporting ajax list append, insert and remove operations and restoring the exact previous state
                ArrayList itemIds     = GetViewStateItemIds();
                ArrayList itemIndexes = GetViewStateItemIndexes();

                // clear any existing child controls
                Controls.Clear();

                int numItems = (int)o;
                int pageSize = this.PageSize;


                for (int i = 0; i < numItems && i < pageSize; i++)
                {
                    // create item
                    RepeaterItem  item    = new RepeaterItem(i, null);
                    InvisibleItem invItem = new InvisibleItem(i, null);

                    try {
                        // initialize item id
                        if (itemIds != null)
                        {
                            item.ID    = Iterator.FormatId((int)itemIds[i * 2]);
                            invItem.ID = Iterator.FormatId((int)itemIds[i * 2 + 1]);
                        }
                        else
                        {
                            item.ID    = Iterator.FormatId(i * 2);
                            invItem.ID = Iterator.FormatId(i * 2 + 1);
                        }
                        // initialize item index
                        if (itemIndexes != null)
                        {
                            item.ItemIndex    = (int)itemIndexes[i * 2];
                            invItem.ItemIndex = (int)itemIndexes[i * 2 + 1];
                        }
                    } catch (ArgumentOutOfRangeException) {
                        throw new HEMessageException(MR.GetMessage(MessageId.AjaxListModified, "List Records", this.ID));
                    }

                    // initialize item from template
                    ItemTemplate.InstantiateIn(item);
                    InvisibleTemplate.InstantiateIn(invItem);
                    // add item to the child controls collection
                    Controls.Add(item);
                    Controls.Add(invItem);
                }
            }
        }
        public OSDataGrid()
            : base()
        {
            AllowPaging       = true;
            AllowCustomPaging = true;

            RtWidget             = new ListRecordRtWidget(this);
            _viewStateAttributes = new ViewStateAttributes(this, Attributes, ViewState);
        }
        protected override void Render(HtmlTextWriter writer)
        {
            AjaxEventsHelper.AddAjaxEventAttribute(this, AjaxEventType.onAjaxClick, ClientID, UniqueID, "__OSVSTATE", ViewStateAttributes.InlineAttributes);
            ViewStateAttributes.InheritInlineAttributes();
            ViewStateAttributes.InlineAttributes.Add("class", _isEmpty ? (string.IsNullOrEmpty(CssClass) ? CssClass : CssClass + " ") + "Empty" : CssClass);

            // Render of the datagrid will be delegated in the child OSDataGridTable control
            base.Render(writer);
        }
        protected override void Render(HtmlTextWriter writer)
        {
            var RenderWrapperTag = Attributes["RenderWrapperTag"] != "false";

            object o       = ViewStateAttributes.GetFromViewState("NumItems", null);
            bool   isEmpty = o == null || (o != null && (int)o == 0);

            if (RenderWrapperTag)
            {
                writer.Write("<span id=\"" + ClientID + "\"");

                if (isEmpty)
                {
                    if (!string.IsNullOrEmpty(EmptyMessageStyle))
                    {
                        writer.Write(" class=\"" + EmptyMessageStyle + "\"");
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(CssClass))
                    {
                        writer.Write(" class=\"" + CssClass + "\"");
                    }
                }

                writer.Write(">");
            }

            if (UseBullets && !isEmpty)
            {
                writer.Write("<ul>");
            }
            foreach (Control ctrl in Controls)
            {
                if (ctrl.GetType() == typeof(RepeaterItem))
                {
                    RenderRepeaterItem(writer, ctrl);
                }
            }
            if (UseBullets && !isEmpty)
            {
                writer.Write("</ul>");
            }

            if (isEmpty)
            {
                RenderEmptyMessage(writer);
            }

            if (RenderWrapperTag)
            {
                writer.Write("</span>");
            }
        }
        protected override void LoadViewState(object savedState)
        {
            base.LoadViewState(savedState);

            // check if we need to ensure child controls for this iterator for running onSubmits
            if ((bool)ViewStateAttributes.GetFromViewState("EnsureChildControls", false))
            {
                ViewState.Remove("EnsureChildControls");
                EnsureChildControls();
            }
        }
        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();
        }
        // override to create repeated items from DataSource
        protected override void OnDataBinding(EventArgs e)
        {
            base.OnDataBinding(e);

            if (!Visible)
            {
                return;
            }
            if (DataSource != null)
            {
                _isDataBinding = true;

                // clear selected index
                SelectedIndex = -1;
                // clear widget viewstate storage variable
                ClearViewStateStorage(this, e);
                // clear any row ids and item indexes, since we are rebuilding all the list
                ClearViewStateRowIdsandItemIndexes();
                // clear any existing child controls
                Controls.Clear();
                // clear any previous viewstate for existing child controls
                ClearChildViewState();

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

                // iterate DataSource creating a new item for each data item
                int i        = 0;
                int pageSize = this.PageSize;
                while (DataSource.MoveNext() && i < pageSize)
                {
                    CreateItem(DataSource, i);
                    i++;
                }
                // store the number of items created in viewstate for postback scenarios
                object o = ViewStateAttributes.GetFromViewState("NumItems", null);
                if (i > 0 || o != null)
                {
                    ViewStateAttributes.SetInViewState("NumItems", i, null);
                }
                // prevent child controls from being created again
                ChildControlsCreated = true;

                _isDataBinding = false;

                DataSource.EndIteration();
            }
        }
Exemple #8
0
        public string GetValue()
        {
            string s = Attributes["value"];

            if (s != null)
            {
                return(s);
            }
            s = ViewStateAttributes.GetFromViewState("value", null) as string;
            if (s != null)
            {
                return(s);
            }
            return(string.Empty);
        }
        private void InsertItem(int itemIndex, object dataItem, bool selectItem)
        {
            // check if the current page is full
            IOSList rl = DataSource;

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

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

            // create an item at the end of the list (and don't databind...)
            CreateItem(dataItem, itemIndex, false);

            // update item count
            ViewStateAttributes.SetInViewState("NumItems", ItemCount, null);

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

            var previousSelectedIndex   = SelectedIndex;
            var previousDataSourceIndex = rl.CurrentRowNumber;

            SelectedIndex = itemIndex;

            // set the record list position
            rl.SetPosition(itemIndex);

            // databind the created item
            DataBindLastCreatedItem();

            if (!selectItem)
            {
                // revert the record list position
                rl.SetPosition(previousDataSourceIndex);
                SelectedIndex = previousSelectedIndex;
            }
        }
 public Iterator() : base()
 {
     RtWidget             = new ListRecordRtWidget(this);
     _viewStateAttributes = new ViewStateAttributes(this, Attributes, ViewState);
 }
Exemple #11
0
 public OSUserControl() : base()
 {
     _viewStateAttributes = new ViewStateAttributes(this, Attributes, ViewState);
     ControlVisibility    = new ControlVisibility(this, _viewStateAttributes);
 }
 public DropDownList()
     : base()
 {
     _viewStateAttributes = new ViewStateAttributes(this, Attributes, ViewState);
 }
Exemple #13
0
 public CheckBox()
     : base(HtmlTextWriterTag.Input)
 {
     _viewStateAttributes = new ViewStateAttributes(this, Attributes, ViewState);
 }
 protected OSPageViewState(bool quirksMode) : base(quirksMode)
 {
     _viewStateAttributes = new ViewStateAttributes(ViewState);
 }
 public Button()
     : base()
 {
     _viewStateAttributes = new ViewStateAttributes(this, Attributes, ViewState);
 }
Exemple #16
0
 public ListBox() : base()
 {
     _viewStateAttributes = new ViewStateAttributes(this, Attributes, ViewState);
 }
 public void EnsureChildControlsOnPostback()
 {
     ViewStateAttributes.SetInViewState("EnsureChildControls", true, false);
 }
Exemple #18
0
 public RadioButton()
     : base(System.Web.UI.HtmlTextWriterTag.Input)
 {
     _viewStateAttributes = new ViewStateAttributes(this, Attributes, ViewState);
 }
 public ControlVisibility(Control owner, ViewStateAttributes viewState)
 {
     this.owner     = owner;
     this.viewState = viewState;
 }