コード例 #1
0
        /// <summary>
        /// 创建自定义分页导航
        /// </summary>
        /// <param name="e">GridViewRowEventArgs,它包含事件数据</param>
        private void CreateCustomPagerRow(GridViewRowEventArgs e)
        {
            e.Row.Cells[0].Controls.Clear();

            #region 显示: 共 234 篇文章

            e.Row.Cells[0].Controls.Add(new LiteralControl("共&nbsp;"));

            Label LblRowsCount = new Label();
            LblRowsCount.ID = "LblRowsCount";
            LblRowsCount.Text = VirtualItemCount.ToString();
            LblRowsCount.Font.Bold = true;

            e.Row.Cells[0].Controls.Add(LblRowsCount);

            e.Row.Cells[0].Controls.Add(new LiteralControl("&nbsp;" + this.ItemUnit + this.ItemName));
            e.Row.Cells[0].Controls.Add(new LiteralControl("&nbsp;&nbsp;"));

            #endregion

            #region 显示: 首页 上一页 下一页 尾页

            LinkButton LbtnFirst = new LinkButton();
            LbtnFirst.CommandName = "Page";
            LbtnFirst.CommandArgument = "First";
            LbtnFirst.Enabled = !(this.PageIndex == 0);
            LbtnFirst.Text = "首页";
            e.Row.Cells[0].Controls.Add(LbtnFirst);
            e.Row.Cells[0].Controls.Add(new LiteralControl("&nbsp;"));

            LinkButton LbtnPrev = new LinkButton();
            LbtnPrev.CommandName = "Page";
            LbtnPrev.CommandArgument = "Prev";
            LbtnPrev.Enabled = !(this.PageIndex == 0);
            LbtnPrev.Text = "上一页";
            e.Row.Cells[0].Controls.Add(LbtnPrev);
            e.Row.Cells[0].Controls.Add(new LiteralControl("&nbsp;"));

            LinkButton LbtnNext = new LinkButton();
            LbtnNext.CommandName = "Page";
            LbtnNext.CommandArgument = "Next";
            LbtnNext.Enabled = !(this.PageIndex == this.PageCount - 1);
            LbtnNext.Text = "下一页";
            e.Row.Cells[0].Controls.Add(LbtnNext);
            e.Row.Cells[0].Controls.Add(new LiteralControl("&nbsp;"));

            LinkButton LbtnLast = new LinkButton();
            LbtnLast.CommandName = "Page";
            LbtnLast.CommandArgument = "Last";
            LbtnLast.Enabled = !(this.PageIndex == this.PageCount - 1);
            LbtnLast.Text = "尾页";
            e.Row.Cells[0].Controls.Add(LbtnLast);

            e.Row.Cells[0].Controls.Add(new LiteralControl("&nbsp;&nbsp;"));

            if (IsHoldState)
            {
                LbtnFirst.Click += new EventHandler(LbtnFirst_Click);
                LbtnPrev.Click += new EventHandler(LbtnPrev_Click);
                LbtnNext.Click += new EventHandler(LbtnNext_Click);
                LbtnLast.Click += new EventHandler(LbtnLast_Click);
            }

            #endregion

            #region 显示: 页次:23/45页

            e.Row.Cells[0].Controls.Add(new LiteralControl("页次:"));

            Label LblCurrentPage = new Label();
            LblCurrentPage.Text = Convert.ToString(this.PageIndex + 1);
            LblCurrentPage.Font.Bold = true;
            LblCurrentPage.ForeColor = System.Drawing.Color.Red;
            e.Row.Cells[0].Controls.Add(LblCurrentPage);

            e.Row.Cells[0].Controls.Add(new LiteralControl("/"));

            Label LblTotalPages = new Label();
            LblTotalPages.Text = Convert.ToString(this.PageCount);
            LblTotalPages.Font.Bold = true;
            e.Row.Cells[0].Controls.Add(LblTotalPages);

            e.Row.Cells[0].Controls.Add(new LiteralControl("页"));
            e.Row.Cells[0].Controls.Add(new LiteralControl("&nbsp;&nbsp;"));

            #endregion

            #region 显示: 20 篇文章/页
            TextBox TxtMaxPerPage = new TextBox();
            TxtMaxPerPage.ApplyStyleSheetSkin(Page);
            TxtMaxPerPage.MaxLength = 3;
            TxtMaxPerPage.Width = 22;
            TxtMaxPerPage.Text = Convert.ToString(this.PageSize);
            TxtMaxPerPage.AutoPostBack = true;
            TxtMaxPerPage.TextChanged += new EventHandler(this.TxtMaxPerPage_TextChanged);
            e.Row.Cells[0].Controls.Add(TxtMaxPerPage);

            e.Row.Cells[0].Controls.Add(new LiteralControl(this.ItemUnit + this.ItemName + "/页"));
            e.Row.Cells[0].Controls.Add(new LiteralControl("&nbsp;&nbsp;"));

            #endregion

            #region 显示: 转到第  页
            e.Row.Cells[0].Controls.Add(new LiteralControl("转到第"));

            if (this.PageCount < 10)
            {
                DropDownList DropCurrentPage = new DropDownList();
                DropCurrentPage.ApplyStyleSheetSkin(Page);
                DropCurrentPage.AutoPostBack = true;
                DropCurrentPage.SelectedIndexChanged += new EventHandler(this.DropCurrentPage_SelectedIndexChanged);
                ArrayList dropValues = new ArrayList();
                for (int i = 1; i <= this.PageCount; i++)
                {
                    dropValues.Add(i);
                }
                DropCurrentPage.DataSource = dropValues;
                DropCurrentPage.DataBind();
                DropCurrentPage.SelectedIndex = this.PageIndex;
                e.Row.Cells[0].Controls.Add(DropCurrentPage);
            }
            else
            {
                TextBox TxtCurrentPage = new TextBox();
                TxtCurrentPage.ApplyStyleSheetSkin(Page);
                TxtCurrentPage.Width = 30;
                TxtCurrentPage.Text = Convert.ToString(this.PageIndex + 1);
                TxtCurrentPage.AutoPostBack = true;
                TxtCurrentPage.TextChanged += new EventHandler(this.TxtCurrentPage_TextChanged);
                e.Row.Cells[0].Controls.Add(TxtCurrentPage);
            }
            e.Row.Cells[0].Controls.Add(new LiteralControl("页"));

            #endregion
        }