打造最便捷的异步分页技术(提供下载)

一、建一个项目(以WebForm为例)

配置文件配置(注意您自己的路径)

二、在页面上生成分页布局代码

1)后端代码

        public string Pager{

            get;

            set;

        }

        private void Page_Load(object sender, EventArgs e)

        {

            

            using (var db=Db.CreateDefaultDb()) {

                var mqlJoin=ScoreSet.SelectAll()

                    .InnerJoin(StudentSet.Select(StudentSet.Name))

                    .InnerJoin(ClassSet.Select(ClassSet.ID.AS("ClassID"),ClassSet.ClassName))

                    .ON(ScoreSet.StudentID.Equal(StudentSet.ID)

                        .And(StudentSet.ClassID.Equal(ClassSet.ID) )

                       );

                this.Pager=Moon.Orm.Util.Pager.GetWebPager(db,"SmallPage.aspx","content",mqlJoin,3,null);

            }

        }

 

2)前端代码

<%@ Page

    Language           = "C#"

    AutoEventWireup    = "false"

    Inherits           = "Moon.Pager.Default"

    ValidateRequest    = "false"

    EnableSessionState = "false"

%>





<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

    <head>

        <title>Moon.Pager</title>



         <script src="http://common.cnblogs.com/script/jquery.js" type="text/javascript"></script>



    </head>

    <body>

        <div id="content"></div>

        <%=this.Pager%>

    </body>

</html>

 

三、加一个异步请求数据的小页面

1)后端代码

public  DictionaryList List;

        private void Page_Load(object sender, System.EventArgs e)

        {

            using (var db=Db.CreateDefaultDb()) {

                var mqlJoin=ScoreSet.SelectAll()

                    .InnerJoin(StudentSet.Select(StudentSet.Name))

                    .InnerJoin(ClassSet.Select(ClassSet.ID.AS("ClassID"),ClassSet.ClassName))

                    .ON(ScoreSet.StudentID.Equal(StudentSet.ID)

                        .And(StudentSet.ClassID.Equal(ClassSet.ID) )

                       );

                this.List=Moon.Orm.Util.Pager.GetOneWebPagesData(db,mqlJoin,null);

            }

        }

 

2)前端代码(SmallPage.aspx:对应前面的代码)

<%@ Page

    Language           = "C#"

    AutoEventWireup    = "false"

    Inherits           = "Moon.Pager.SmallPage"

    ValidateRequest    = "false"

    EnableSessionState = "false" -----------下载文件中没有,请你自己加上

%>

<%

foreach(var a in this.List){%>

<p><%=a["ID"]%>&nbsp;<%=a["Name"]%></p>

<%}%>

 

四、效果图

五、下载地址

http://pan.baidu.com/share/link?shareid=915781506&uk=353229276

六、在线体验(其实你们来在线体验页面,我是知道的,来了就留个言吧)

http://172321.dowei8.com

七、内核代码

打造最便捷的异步分页技术(提供下载)
        /// <summary>

        /// 获取一个网页形式的分页布局

        /// </summary>

        /// <param name="db">db引擎</param>

        /// <param name="smallPageURL">去这个页面地址取数据</param>

        /// <param name="contentDomID">用于存放数据的domID</param>

        /// <param name="mql">mql语句</param>

        /// <param name="onePageDataCount">每页的数据条数</param>

        /// <param name="oneOrderbyFieldName">如果没有则填写null(提示:似乎只有sqlserver中可能会用上)</param>

        /// <returns>分页布局</returns>

        public static string GetWebPager(Db db,string smallPageURL,string contentDomID,MQLBase mql,int onePageDataCount,string oneOrderbyFieldName){

            string scriptsLink="<div id='pageNav'></div><script src='http://page-nav-js-jquery.googlecode.com/files/pagenav.min.js'></script>";

            string css="<style type='text/css' media='screen'>a { color:#2B4A78; text-decoration:none; }a:hover { color:#2B4A78;text-decoration:underline; }a:focus, input:focus {outline-style:none; outline-width:medium; }.pageNum{border: 1px solid #999;padding:2px 8px;display: inline-block;}.cPageNum{font-weight: bold;padding:2px 5px;}#pageNav a:hover{text-decoration:none;background: #fff4d8; }</style>";

            long sumPageCount;

            string sql=mql.ToParametersSQL();

            string countSql="SELECT COUNT(0) FROM ("+sql+")  T_MOON_Search0";

            var parameters=mql.Parameters.ToArray();

            var countData=db.ExecuteSqlToScalar(countSql,parameters);

            var sumDataCount=Convert.ToInt32(countData);

            sumPageCount=sumDataCount/onePageDataCount;

            string script="<script>var _perCount="+onePageDataCount+";var _pageSum="+sumPageCount+";var _listDivID='"+contentDomID+"';var _listActionPlace='"+smallPageURL+"';function GetPage(currentPageIndex,pageSum){$.ajax({url:_listActionPlace,async:true,cache:false,data:{PageIndex:currentPageIndex,onePageDataCount:"+onePageDataCount+"},success:function(html){$('#'+_listDivID).html('');$('#'+_listDivID).html(html);}});}$(function(){pageNav.pre='前一页';pageNav.next='下一页';pageNav.fn=function(currentPageIndex,pageSum){GetPage(currentPageIndex,pageSum);};pageNav.go(1,_pageSum);});</script>";

            return scriptsLink+css+script;

        }

        /// <summary>

        /// smallPageURL中的数据

        /// </summary>

        /// <param name="db">db引擎</param>

        /// <param name="mql">mql</param>

        /// <param name="oneOrderbyFieldName">如果没有则填写null(提示:似乎只有sqlserver中可能会用上)</param>

        /// <returns></returns>

        public static DictionaryList GetOneWebPagesData(Db db,MQLBase mql,string oneOrderbyFieldName){

            long sumPageCount;

            HttpRequest Request=System.Web.HttpContext.Current.Request;

            long pageIndex=Convert.ToInt64(Request["PageIndex"]);

            int onePageDataCount=Convert.ToInt32(Request["onePageDataCount"]);

            return db.GetPagerToDictionList(mql,out sumPageCount,pageIndex,onePageDataCount,oneOrderbyFieldName);

        }
View Code

 

 

 

你可能感兴趣的:(分页技术)