private IDictionary <string, bool> GetVisibilityDictionary(bool createIfNotExists)
        {
            var result = (IDictionary <string, bool>)viewState.GetFromViewState(INPUT_VISIBILITY_KEY_IN_VIEWSTATE, null);

            if ((result == null) && createIfNotExists)
            {
                result = new Dictionary <string, bool>();
                viewState.SetInViewState(INPUT_VISIBILITY_KEY_IN_VIEWSTATE, result, null);
            }

            return(result);
        }
        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();
            }
        }
        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;
            }
        }
예제 #5
0
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            if (Enabled && !_registeredPostBack)
            {
                // only register requires postback event once per request, otherwise in multiple partial refreshes the
                // control's ids will appear multiple times in the Viewstate in the key __ControlsRequirePostBackKey__
                Page.RegisterRequiresPostBack(this);
                _registeredPostBack = true;
            }
            string value = Attributes["value"];

            if (OSPage.IsAjaxRequest && value == null)
            {
                //#109916 - Get value from the viewstate, since if the radio is inside a table records the GetRadioValue() will return null
                value = (string)ViewState["value"];
            }

            ViewStateAttributes.SetInViewState("value", value, null);
        }
 public void EnsureChildControlsOnPostback()
 {
     ViewStateAttributes.SetInViewState("EnsureChildControls", true, false);
 }