예제 #1
0
        /// <summary>建立子控件</summary>
        protected override void CreateChildControls()
        {
            // 当且仅当总记录数TotalRowCount准备好之后才创建子控件
            if (TotalRowCount <= 0)
            {
                return;
            }

            Controls.Clear();

            IPagedDataSource pagedDataSource = this;

            PagerSettings pagerSettings = PagerSettings;

            if (PagerTemplate != null)
            {
                // 分页模版输出
                DataPagerItem item = new DataPagerItem();
                PagerTemplate.InstantiateIn(item);

                Controls.Add(item);

                // 必须在加入Controls后再绑定,否则会因为没有关联Page而失败
                // 每次完成创建子控件后马上绑定
                item.DataItem = this;
                item.DataBind();
                item.DataItem = null;
            }
            else
            {
                // 分页控件输出
                Table    child = new Table();
                TableRow row2  = new TableRow();
                switch (pagerSettings.Mode)
                {
                case PagerButtons.NextPrevious:
                    CreateNextPrevPager(row2, pagedDataSource, false);
                    break;

                case PagerButtons.Numeric:
                    CreateNumericPager(row2, pagedDataSource, false);
                    break;

                case PagerButtons.NextPreviousFirstLast:
                    CreateNextPrevPager(row2, pagedDataSource, true);
                    break;

                case PagerButtons.NumericFirstLast:
                    CreateNumericPager(row2, pagedDataSource, true);
                    break;
                }

                child.Rows.Add(row2);
                Controls.Add(child);
            }
        }
예제 #2
0
        /// <summary>
        /// 建立子控件
        /// </summary>
        protected override void CreateChildControls()
        {
            // 当且仅当总记录数TotalRowCount准备好之后才创建子控件
            if (TotalRowCount <= 0) return;

            Controls.Clear();

            IPagedDataSource pagedDataSource = this;

            PagerSettings pagerSettings = PagerSettings;
            if (PagerTemplate != null)
            {
                // 分页模版输出
                DataPagerItem item = new DataPagerItem();
                PagerTemplate.InstantiateIn(item);

                Controls.Add(item);

                // 必须在加入Controls后再绑定,否则会因为没有关联Page而失败
                // 每次完成创建子控件后马上绑定
                item.DataItem = this;
                item.DataBind();
                item.DataItem = null;
            }
            else
            {
                // 分页控件输出
                Table child = new Table();
                TableRow row2 = new TableRow();
                switch (pagerSettings.Mode)
                {
                    case PagerButtons.NextPrevious:
                        CreateNextPrevPager(row2, pagedDataSource, false);
                        break;

                    case PagerButtons.Numeric:
                        CreateNumericPager(row2, pagedDataSource, false);
                        break;

                    case PagerButtons.NextPreviousFirstLast:
                        CreateNextPrevPager(row2, pagedDataSource, true);
                        break;

                    case PagerButtons.NumericFirstLast:
                        CreateNumericPager(row2, pagedDataSource, true);
                        break;
                }

                child.Rows.Add(row2);
                Controls.Add(child);
            }
        }