Example #1
0
        /// <summary>
        /// 呈现本元素的数据
        /// </summary>
        /// <param name="writer"></param>
        protected override void RenderTagData(System.IO.TextWriter writer)
        {
            IEnumerable array = Utility.GetResolvedDataSource(this.From.GetValue());
            int         index = 0;
            LoopIndex   li    = new LoopIndex(0);

            if (this.Index != null)
            {
                this.Index.Value = li;
            }
            if (array != null)
            {
                IEnumerator list      = array.GetEnumerator();
                int         groupSize = this.GroupSize == null ? 0 : TypeConvert.ToInt32(this.GroupSize.GetTextValue());
                if (groupSize > 1)
                {
                    list = Utility.SplitToGroup(list, groupSize);
                }

                list.Reset();
                if (list.MoveNext())
                {
                    li.IsLast = false;
                    while (!li.IsLast)
                    {
                        object v = list.Current;
                        li.Value   = ++index;
                        li.IsFirst = (index == 1);
                        li.IsLast  = !list.MoveNext();
                        if (this.Index != null)
                        {
                            this.Index.Reset();
                        }
                        if (this.Item != null)
                        {
                            this.Item.Value = v;
                        }
                        base.RenderTagData(writer);
                    }
                }
            }
            if (index == 0 && this.Else != null)
            {
                //没有数据则输出Else节点的数据
                this.Else.Render(writer);
            }
        }
Example #2
0
        /// <summary>
        /// 呈现本元素的数据
        /// </summary>
        /// <param name="writer"></param>
        protected override void RenderTagData(System.IO.TextWriter writer)
        {
            decimal from  = Utility.ConverToDecimal(this.From.Value.GetValue());
            decimal step  = this.Step == null ? 1 : Utility.ConverToDecimal(this.Step.Value.GetValue());
            decimal to    = Utility.ConverToDecimal(this.To.Value.GetValue());
            decimal index = from;

            LoopIndex li = new LoopIndex(index);

            if (this.Index != null)
            {
                this.Index.Value = li;
            }
            if (step >= 0)
            {
                while (index <= to)
                {
                    li.Value   = index;
                    li.IsFirst = (index == from);
                    li.IsLast  = (index == to);
                    if (this.Index != null)
                    {
                        this.Index.Variable.Reset();
                    }
                    base.RenderTagData(writer);
                    index += step;
                }
            }
            else
            {
                while (index >= to)
                {
                    li.Value   = index;
                    li.IsFirst = (index == from);
                    li.IsLast  = (index == to);
                    if (this.Index != null)
                    {
                        this.Index.Variable.Reset();
                    }
                    base.RenderTagData(writer);
                    index += step;
                }
            }
        }