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

一、建一个项目(以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.Pagertitle>

         <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"]%> <%=a["Name"]%>p>
<%}%>

 

四、效果图

五、下载地址

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

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

http://172321.dowei8.com

七、内核代码

        /// 
        /// 获取一个网页形式的分页布局
        /// 
        /// db引擎
        /// 去这个页面地址取数据
        /// 用于存放数据的domID
        /// mql语句
        /// 每页的数据条数
        /// 如果没有则填写null(提示:似乎只有sqlserver中可能会用上)
        /// 分页布局
        public static string GetWebPager(Db db,string smallPageURL,string contentDomID,MQLBase mql,int onePageDataCount,string oneOrderbyFieldName){
            string scriptsLink="";
            string css="";
            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="";
            return scriptsLink+css+script;
        }
        /// 
        /// smallPageURL中的数据
        /// 
        /// db引擎
        /// mql
        /// 如果没有则填写null(提示:似乎只有sqlserver中可能会用上)
        /// 
        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

 

 

 

你可能感兴趣的:(打造最便捷的异步分页技术(提供下载))