zoukankan      html  css  js  c++  java
  • gridview 分页

       protected void PageButtonClick(object sender, EventArgs e)
        {
            LinkButton clickedButton = ((LinkButton)sender);
            if (clickedButton.CommandName == "first")
            {
                gvshow.PageIndex = 0;
            }
            else if (clickedButton.CommandName == "next")
            {
                if (gvshow.PageIndex < gvshow.PageCount - 1)
                {
                    gvshow.PageIndex += 1;
                }
            }
            else if (clickedButton.CommandName == "previous")
            {
                if (gvshow.PageIndex >= 1)
                {
                    gvshow.PageIndex -= 1;
                }
            }
            else if (clickedButton.CommandName == "last")
            {
                gvshow.PageIndex = gvshow.PageCount - 1;
            }
            BindData();
        }   

    protected void gvshow_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Pager)
            {
                Label label_Index = new Label();
                LinkButton Button_IndexFirst = new LinkButton();
                LinkButton Button_IndexLast = new LinkButton();
                LinkButton Button_IndexNext = new LinkButton();
                LinkButton Button_IndexPrevious = new LinkButton();

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

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

                Button_IndexNext.Click += new EventHandler(PageButtonClick);

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

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

                label_Index.Text = "当前为第" + (gvshow.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.Add(label_Index);
            }
        }

  • 相关阅读:
    SVN 主干(trunk)、分支(branch )、标记(tag)
    HTML的img标签:alt属性和title属性
    HTML的img标签:alt属性和title属性
    Eclipse远程调试Tomcat
    Eclipse远程调试Tomcat
    使用 Eclipse 远程调试 Java 应用程序
    使用 Eclipse 远程调试 Java 应用程序
    14.Windows 与 Linux 文件共享
    13.远程登录 Linux
    12.Linux 网络配置
  • 原文地址:https://www.cnblogs.com/lgxll/p/2811595.html
Copyright © 2011-2022 走看看