Exemple #1
0
        private void RenderDataNodes(HtmlTextWriter writer, IEnumerable dataItems, int depth, int index = 0, bool renderListTag = true)
        {
            if (dataItems == null || (dataItems is ICollection && ((ICollection)dataItems).Count < 1))
            {
                return;
            }

            if (Zongsoft.Common.TypeExtension.IsAssignableFrom(typeof(ICollection <>), dataItems.GetType()))
            {
                var property = dataItems.GetType().GetProperty("Count", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

                if (property != null && Zongsoft.Common.Convert.ConvertValue <int>(property.GetValue(dataItems)) < 1)
                {
                    return;
                }
            }

            if (renderListTag)
            {
                var cssClass = this.ListCssClass ?? this.ListCssClass;

                if (this.IsDropdown)
                {
                    cssClass = Utility.ResolveCssClass(":menu", () => cssClass);
                }

                if (!string.IsNullOrWhiteSpace(cssClass))
                {
                    writer.AddAttribute(HtmlTextWriterAttribute.Class, cssClass);
                }

                writer.RenderBeginTag(this.GetListTagName());
            }

            foreach (var dataItem in dataItems)
            {
                FormExtension.PushDataItem(this.Page, dataItem, index);

                this.RenderNodeTemplate(writer, new TreeViewNodeContainer(this, dataItem, index++, this.GetItemTagName(), this.ItemCssClass)
                {
                    Depth = depth,
                });

                FormExtension.PopDataItem(this.Page);
            }

            if (renderListTag)
            {
                writer.RenderEndTag();
            }
        }
Exemple #2
0
        private void RenderTableBody(HtmlTextWriter writer)
        {
            //生成表体标记(开始)
            writer.RenderBeginTag(HtmlTextWriterTag.Tbody);

            if (Utility.IsEmptyCollection(this.DataSource))
            {
                if (_emptyTemplate != null)
                {
                    var tr = new System.Web.UI.HtmlControls.HtmlTableRow();
                    var td = new System.Web.UI.HtmlControls.HtmlTableCell()
                    {
                        ColSpan = this.Columns.Count,
                    };

                    tr.Controls.Add(td);
                    _emptyTemplate.InstantiateIn(td);
                    tr.RenderControl(writer);
                }
            }
            else
            {
                IEnumerable dataSource = this.DataSource as IEnumerable;

                if (dataSource == null)
                {
                    this.GenerateRow(writer, this.DataSource, 1);
                }
                else
                {
                    int index = 0;
                    foreach (var dataItem in dataSource)
                    {
                        FormExtension.PushDataItem(this.Page, dataItem, index);
                        this.GenerateRow(writer, dataItem, index++);
                        FormExtension.PopDataItem(this.Page);
                    }
                }
            }

            //生成表体标记(结束)
            writer.RenderEndTag();
        }
Exemple #3
0
        protected override void RenderContent(HtmlTextWriter writer)
        {
            if (Utility.IsEmptyCollection(this.DataSource))
            {
                if (_emptyTemplate != null)
                {
                    using (var literal = new Literal())
                    {
                        _emptyTemplate.InstantiateIn(literal);
                        literal.RenderControl(writer);
                    }
                }

                return;
            }

            IEnumerable dataItems = this.DataSource as IEnumerable;

            if (dataItems == null || dataItems.GetType() == typeof(string))
            {
                var item = new DataItemContainer <ListView>(this, this.DataSource, 0);
                this.RenderItem(writer, item);
            }
            else
            {
                int index = 0;

                foreach (var dataItem in dataItems)
                {
                    FormExtension.PushDataItem(this.Page, dataItem, index);

                    var item = new DataItemContainer <ListView>(this, dataItem, index++);
                    this.RenderItem(writer, item);

                    FormExtension.PopDataItem(this.Page);
                }
            }
        }