protected override void OnPreRender(EventArgs e) {
            base.OnPreRender(e);

            // Dummy control to which we parent all the data item controls
            Control containerControl = new Control();

            IEnumerable dataItems = ViewData.Eval(Name) as IEnumerable;
            bool hasData = false;
            if (dataItems != null) {
                int index = 0;
                foreach (object dataItem in dataItems) {
                    hasData = true;
                    RepeaterItem repeaterItem = new RepeaterItem(index, dataItem) {
                        ViewData = new ViewDataDictionary(dataItem),
                    };
                    ItemTemplate.InstantiateIn(repeaterItem);
                    containerControl.Controls.Add(repeaterItem);

                    index++;
                }
            }

            if (!hasData) {
                // If there was no data, instantiate the EmptyDataTemplate
                Control emptyDataContainer = new Control();
                EmptyDataTemplate.InstantiateIn(emptyDataContainer);
                containerControl.Controls.Add(emptyDataContainer);
            }

            Controls.Add(containerControl);

            containerControl.DataBind();
        }
Beispiel #2
0
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);

            // Dummy control to which we parent all the data item controls
            Control containerControl = new Control();

            IEnumerable dataItems = ViewData.Eval(Name) as IEnumerable;
            bool        hasData   = false;

            if (dataItems != null)
            {
                int index = 0;
                foreach (object dataItem in dataItems)
                {
                    hasData = true;
                    RepeaterItem repeaterItem = new RepeaterItem(index, dataItem)
                    {
                        ViewData = new ViewDataDictionary(dataItem),
                    };
                    ItemTemplate.InstantiateIn(repeaterItem);
                    containerControl.Controls.Add(repeaterItem);

                    index++;
                }
            }

            if (!hasData)
            {
                // If there was no data, instantiate the EmptyDataTemplate
                Control emptyDataContainer = new Control();
                EmptyDataTemplate.InstantiateIn(emptyDataContainer);
                containerControl.Controls.Add(emptyDataContainer);
            }

            Controls.Add(containerControl);

            containerControl.DataBind();
        }