none
采用自定义分页的gridview 为什么无法触发PageIndexChanging 事件 RRS feed

  • 问题

  • allowpaging="true"

    protected void chexiaopjinf_gv_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Pager)
            {
                Label label_Index = new Label();
                Label label_go = new Label();
                Label label_page = new Label();

                TextBox PageIndex_tb = new TextBox();
                LinkButton Button_GO = new LinkButton();

                LinkButton Button_IndexFirst = new LinkButton();
                LinkButton Button_IndexLast = new LinkButton();
                LinkButton Button_IndexNext = new LinkButton();
                LinkButton Button_IndexPrevious = new LinkButton();

                label_go.Text = "      转到第";
                label_page.Text = " 页      ";

                PageIndex_tb.Width = Unit.Pixel(20);
                PageIndex_tb.Font.Name = "宋体";
                PageIndex_tb.Font.Size = FontUnit.Parse("9pt");

                Session["canceledpageindex"] = PageIndex_tb;

                Button_GO.Text = "GO";
                Button_GO.CommandName = "GO";
                Button_GO.ForeColor = System.Drawing.Color.White;
                Button_GO.Click += new EventHandler(PageButtonClick);

                Button_IndexFirst.Text = "第一页 ";
                Button_IndexFirst.CommandName = "first";
                Button_IndexFirst.ForeColor = System.Drawing.Color.White;
                Button_IndexFirst.Click += new EventHandler(PageButtonClick);

                Button_IndexNext.Text = "   下一页 ";
                Button_IndexNext.CommandName = "next";
                Button_IndexNext.ForeColor = System.Drawing.Color.White;

                Button_IndexNext.Click += new EventHandler(PageButtonClick);

                Button_IndexPrevious.Text = "上一页 ";
                Button_IndexPrevious.CommandName = "previous";
                Button_IndexPrevious.ForeColor = System.Drawing.Color.White;
                Button_IndexPrevious.Click += new EventHandler(PageButtonClick);

                Button_IndexLast.Text = "最末页 ";
                Button_IndexLast.CommandName = "last";
                Button_IndexLast.ForeColor = System.Drawing.Color.White;
                Button_IndexLast.Click += new EventHandler(PageButtonClick);

                label_Index.Text = "当前为第" + (chexiaopjinf_gv.PageIndex + 1) + "页, 共有" + ((GridView)sender).PageCount + "页";
                e.Row.Controls[0].Controls[0].Controls[0].Controls[0].Controls.AddAt(0, (Button_IndexFirst));
                e.Row.Controls[0].Controls[0].Controls[0].Controls[0].Controls.AddAt(1, (Button_IndexPrevious));

                int controlTmp = e.Row.Controls[0].Controls[0].Controls[0].Controls.Count - 1;
                e.Row.Controls[0].Controls[0].Controls[0].Controls[controlTmp].Controls.Add(Button_IndexNext);
                e.Row.Controls[0].Controls[0].Controls[0].Controls[controlTmp].Controls.Add(Button_IndexLast);

                e.Row.Controls[0].Controls[0].Controls[0].Controls[controlTmp].Controls.Add(label_Index);

                e.Row.Controls[0].Controls[0].Controls[0].Controls[controlTmp].Controls.Add(label_go);
                e.Row.Controls[0].Controls[0].Controls[0].Controls[controlTmp].Controls.Add(PageIndex_tb);
                e.Row.Controls[0].Controls[0].Controls[0].Controls[controlTmp].Controls.Add(label_page);
                e.Row.Controls[0].Controls[0].Controls[0].Controls[controlTmp].Controls.Add(Button_GO);

                //e.Row.Controls[0].Controls.Add(label_Index);
            }
        }

        protected void PageButtonClick(object sender, EventArgs e)
        {
            LinkButton clickedButton = ((LinkButton)sender);

            if (clickedButton.CommandName == "first")
            {
                chexiaopjinf_gv.PageIndex = 0;
            }
            else if (clickedButton.CommandName == "next")
            {
                if (chexiaopjinf_gv.PageIndex < chexiaopjinf_gv.PageCount - 1)
                {
                    chexiaopjinf_gv.PageIndex += 1;
                }
            }
            else if (clickedButton.CommandName == "previous")
            {
                if (chexiaopjinf_gv.PageIndex >= 1)
                {
                    chexiaopjinf_gv.PageIndex -= 1;
                }
            }
            else if (clickedButton.CommandName == "last")
            {
                chexiaopjinf_gv.PageIndex = chexiaopjinf_gv.PageCount - 1;
            }
            else if (clickedButton.CommandName == "GO")//转到某一页
            {
                int lipageidx;

                if (((TextBox)Session["canceledpageindex"]).Text.Trim() == "")
                {
                    lipageidx = 1;
                }
                else
                {
                    int tIndex = int.Parse(((TextBox)Session["canceledpageindex"]).Text.Trim());

                    if (tIndex > chexiaopjinf_gv.PageCount)
                    {
                        tIndex = chexiaopjinf_gv.PageCount;
                    }
                    else if (tIndex < 1)
                    {
                        tIndex = 1;
                    }

                    lipageidx = tIndex - 1;

                }

                chexiaopjinf_gv.PageIndex = lipageidx;

            }

            if (Session["chexiaopjinfquerysql"].ToString() != "")
            {
                chexiaopjinfSqlDataSource.SelectCommand = Session["chexiaopjinfquerysql"].ToString();

            }

            chexiaopjinf_gv.DataBind();
        }

     

    调试时,始终无法执行PageIndexChanging 的代码,请问为什么?

    2011年8月9日 8:05

答案

全部回复