• 我的分页代码


      private void Page_Load(object sender, System.EventArgs e)
      {
       // 在此处放置用户代码以初始化页面
       if(!this.IsPostBack)
       {
        string PageIndex=Request.QueryString["PageIndex"];
        if(PageIndex==null||PageIndex.Length==0)//这种方法判断快一些
        {
         this.BindData(this.Repeater1,1,5);
         this.Label1.Text=this.ViewPage(1,5);
        }
        else
        {
         this.BindData(this.Repeater1,Convert.ToInt32(PageIndex),5);
         this.Label1.Text=this.ViewPage(Convert.ToInt32(PageIndex),5);
        }
       }

      }

      /// <summary>
      /// 数据绑定
      /// </summary>
      /// <param name="rep">Repeater控件</param>
      /// <param name="PageIndex">当前页</param>
      /// <param name="parpage">每页大小</param>
      private void BindData(Repeater rep,int PageIndex,int parpage)
      {
       GJGK.WEB.Business.Conn conn=new GJGK.WEB.Business.Conn(System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]);
       rep.DataSource=conn.Read("tbl_Soft_Softs","*","AddedDate",parpage,PageIndex,0,1,"").Tables[0].DefaultView;
       rep.DataBind();
      }

      /// <summary>
      /// 显示分页
      /// </summary>
      /// <param name="PageIndex">当前页</param>
      /// <param name="parpage">每页大小</param>
      private string ViewPage(int PageIndex,int parpage)
      {
       int[] arr=PageSize(parpage);
       int totalrecord=arr[0];//总的记录数
       int totalpage=arr[1];//总的页数
       string str="";
       string url="Default.aspx";
       if(PageIndex==1)
       {
        if(totalrecord<parpage)
        {
         str+="&nbsp;";
        }
        else
        {
         str+="<span style=\"font-size:12px;color:#cccccc;text-decoration: none;\">首页</span>&nbsp;&nbsp;&nbsp;<span style=\"color:#cccccc;font-size:12px\">上一页</span>&nbsp;&nbsp;&nbsp;<a href=\""+url+"?PageIndex="+(PageIndex+1)+"\" style=\"color:#000000;text-decoration: none;font-size:12px\">下一页</a>&nbsp;&nbsp;&nbsp;<a href=\""+url+"?PageIndex="+totalpage+"\" style=\"font-size:12px;color:#000000;text-decoration: none;\">尾页</a>";
         str+="&nbsp;&nbsp;&nbsp;<span style=\"font-size:12px\">页次:<b><font color=\"red\">"+PageIndex+"</font></b>/<b>"+totalpage+"</b>&nbsp;&nbsp;&nbsp;<b>"+parpage+"</b>条主题/页</span>";
        }
       }
       else if(PageIndex<totalpage)
       {
        str+="<a href=\""+url+"?PageIndex=1\" style=\"font-size:12px;color:#000000;text-decoration: none;\">首页</a>&nbsp;&nbsp;&nbsp;<a href=\""+url+"?PageIndex="+(PageIndex-1)+"\" style=\"color:#000000;text-decoration: none;font-size:12px\">上一页</a>&nbsp;&nbsp;&nbsp;<a href=\""+url+"?PageIndex="+(PageIndex+1)+"\" style=\"color:#000000;text-decoration: none;font-size:12px\">下一页</a>&nbsp;&nbsp;&nbsp;<a href=\""+url+"?PageIndex="+totalpage+"\" style=\"font-size:12px;color:#000000;text-decoration: none;\">尾页</a>";
        str+="&nbsp;&nbsp;&nbsp;<span style=\"font-size:12px\">页次:<b><font color=\"red\">"+PageIndex+"</font></b>/<b>"+totalpage+"</b>&nbsp;&nbsp;&nbsp;<b>"+parpage+"</b>条主题/页</span>";
       }
       else if(PageIndex==totalpage)
       {
        int a=totalrecord%parpage;
        if(a==0)
        {
         a=parpage;
        }
        str+="<a href=\""+url+"?PageIndex=1\" style=\"font-size:12px;color:#000000;text-decoration: none;\">首页</a>&nbsp;&nbsp;&nbsp;<a href=\""+url+"?PageIndex="+(PageIndex-1)+"\" style=\"color:#000000;text-decoration: none;font-size:12px\">上一页</a>&nbsp;&nbsp;&nbsp;<span style=\"font-size:12px;color:#cccccc;text-decoration: none;\">下一页</span>&nbsp;&nbsp;&nbsp;<span style=\"font-size:12px;color:#cccccc;text-decoration: none;\">尾页</span>";
        str+="&nbsp;&nbsp;&nbsp;<span style=\"font-size:12px\">页次:<b><font color=\"red\">"+PageIndex+"</font></b>/<b>"+totalpage+"</b>&nbsp;&nbsp;&nbsp;<b>"+a+"</b>条主题/页</span>";
       }
       else
       {
        str+="<font color=\"red\">当前页没有数据</font>";
       }
       return str;
      }


      /// <summary>
      /// 返回总的页数总条数数组
      /// </summary>
      /// <param name="parpage">每一页的大小</param>
      /// <returns>返回总的页数</returns>
      private int[] PageSize(int parpage)
      {
       GJGK.WEB.Business.Conn conn=new GJGK.WEB.Business.Conn(System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]);
       int totalnum=Convert.ToInt32(conn.Read("tbl_Soft_Softs","*","AddedDate",1,1,1,1,"").Tables[0].Rows[0][0]);
       int totalpage=(int)System.Math.Ceiling(totalnum/Convert.ToDouble(parpage));
       int[] arr=new int[]{totalnum,totalpage};
       return arr;
      }

  • 相关阅读:
    POJ 3616 Milking Time(简单区间DP)
    AizuOJ ALDS1_7_A Rooted Trees(有根树的表达)
    jQuery中 attr() 和 prop() 的区别
    前后端交互模式
    快速排序
    冒泡排序实现
    Vue 组件间进行通信
    JavaScript 数组常用方法
    如何将内网映射到公网?
    javax.mail.AuthenticationFailedException: 535 Login Fail. Please enter your authorization code to login. More information in
  • 原文地址:https://www.cnblogs.com/wang123/p/530791.html
Copyright © 2020-2023  润新知