// 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);
                }
            }
        }
        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();
            }
        }
        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);
        }
        // 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();
            }
        }
예제 #6
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);
        }