zoukankan      html  css  js  c++  java
  • 完美的ASP.NET页面分页控件

    一,引入控件(AspNetPager.dll)

    二,写方法

    /// <summary>
        /// 完美的ASP.NET页面分页控件
        /// </summary>
        /// <param name="PageSize">每页显示的条数</param>
        /// <param name="PageIndex">当前页</param>
        /// <param name="DoCount">是否显示总条数</param>
        /// <param name="RowCount">总条数</param>
        /// <param name="TableName">要显示的数据表名</param>
        /// <param name="PID">数据表的主键</param>
        /// <param name="ColList">显示的字段名</param>
        /// <param name="Condition">条件,主要是WHERE</param>
        /// <param name="OrderBy">排序</param>
        /// <returns>DataSet数据集</returns>   

    public DataSet DoPageList(int PageSize, int PageIndex, bool DoCount, out int RowCount,
    string TableName, string PID, string ColList, string Condition, string OrderBy)
        {

            if (ColList == "" || ColList == null) ColList = "*";
            if (Condition == null || Condition == "") Condition = "";
            if (OrderBy == null || OrderBy == "") OrderBy = "";
            string strSQL = "select * from (select ROWNUM R,A.* from ( select " + ColList + " " + " from " + TableName + " " + Condition + " " + OrderBy + ") A) where R > " + (PageIndex - 1) * PageSize + " and R <=" + PageIndex * PageSize;
            if (DoCount)
            {
                string sqlcount = "select count(1) from " + TableName + " " + Condition + " " + OrderBy;
                object obj = DbFactory.Instance.GetDbHelp().ExecuteScalar(sqlcount);
                if (obj != null)
                {
                    RowCount = int.Parse(obj.ToString());
                }
                else
                {
                    RowCount = 0;
                }
            }
            else
            {
                RowCount = 0;
            }
            return DbFactory.Instance.GetDbHelp().GetDataSet(strSQL);

        }

    三.引用方法

         int RowCount = 0;
            DataSet ds = new DataSet();
            ds = DoPageList(this.AspNetPager1.PageSize, this.AspNetPager1.CurrentPageIndex, true, out RowCount, "codes", "", "", "", "");
            this.GridView1.DataSource = ds;
            this.GridView1.DataBind();
            AspNetPager1.RecordCount = RowCount;
            AspNetPager1.CustomInfoHTML = "&nbsp;<font color=\"blue\"><b>共有:" + RowCount + "条信息,总页数:" + AspNetPager1.PageCount + ",当前位置:第" + AspNetPager1.CurrentPageIndex + "页</b></font>";
            ds.Dispose();

  • 相关阅读:
    互联网协议入门(一)(转)
    程序员的自我修养——操作系统篇(转)
    程序员的自我修养(2)——计算机网络(转)
    里氏替换原则
    Windows Phone 自学笔记 : ApplicationBar
    如何写好代码
    C# 通过操作注册表控制系统 (更新)
    优秀PPT 设计的十大秘诀
    设计模式学习--面向对象的5条设计原则
    SOLID (面向对象设计) From 维基百科
  • 原文地址:https://www.cnblogs.com/juan/p/1440607.html
Copyright © 2011-2022 走看看