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);
            }
        }

  • 相关阅读:
    ReSharper.8.0.14.856注册码
    asp.net 301重定向代码
    WebResource.axd 404 错误
    【原创】asp.net导出word 检索 COM 类工厂中 CLSID 为 {000209FF-0000-0000-C000-000000000046} 的组件失败,原因是出现以下错误: 8000401a
    C#操作word或excel及水晶报表,检索 COM 类工厂中 CLSID 为 {} 的组件时失败,原因是出现以下错误: 80070005
    Repository 设计模式介绍
    将15位身份证转换成18位
    清理数据库木马文件
    Oracle的创建表空间及用户
    使用python脚本执行地理处理工具
  • 原文地址:https://www.cnblogs.com/lgxll/p/2811595.html
Copyright © 2011-2022 走看看