asp.net 无刷新分页实例代码(3)

分页标题#e#

public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}

aspx页面代码:

复制代码 代码如下:


<head runat="server">
    <title>无标题页</title>

<script src="https://www.jb51.net/JS/jquery-latest.js" type="text/javascript"></script>
    <script type="text/javascript">
$(function(){
//-----------------------------------------------------------
function getPageData(pageNo){ //取得某页数据的方法
$.post("PageService.ashx",{"action":"GetPageData","PageNo":pageNo},function(data,status){
if(status=="success"){
$("#Comment").empty();
var comments=$.parseJSON(data); //反序列化json数据。
for(var i=0;i<comments.length;i++){
var row=comments[i];
var li= $("<li>"+row.Name+" : "+row.Phone+"</li>");
$("#Comment").append(li); //每取出一条数据就创建一个li并append到Comment/ul内。
}
}
});
}
//-------------------------------------------------------------------
getPageData(1); //首次进入页面,看到的是第一页的数据
//----------------------------------------------------------------/
//取得所有的页数并且初始化分页按钮
$.post("PageService.ashx",{"action":"GetPageCount"},function(data,status){
if(status=="success"){
var tr1=$("<tr></tr>");
var pageNo=parseInt(data);
for(var i=1;i<=pageNo;i++){
var td=$("<td><a href=''>"+i+"</a></td>");
tr1.append(td);
}
$("#pageNo").append(tr1);
$("#pageNo a").click(function(e){ //页码创建后,就为每一个页码监听一个click事件。
e.preventDefault(); //取消a的默认跳转行为
getPageData($(this).html()); //点击后就去执行取页数据的操作。
});
}
});
//----------------------------------------------------------------------------
});
</script>
</head>
<body>
<table>
    <tr>
        <td>
        <ul></ul>
        </td>
    </tr>
</table>
    <br />
    页数:
    <table></table>
</body>
</html>

ModelConvertHelper.cs(将datatable转换为list通用类)代码:

复制代码 代码如下:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Data;
using System.Reflection;

namespace DAL
{
    public class ModelConvertHelper<T> where T : new ()
    {
        public static IList<T> ConvertToModel(DataTable dt)
        {
         IList<T> ts = new List<T>();
        Type type=typeof(T);
        string tempName = "";
        foreach (DataRow dr in dt.Rows)
        {
            T t = new T();
            // 获得此模型的公共属性
            PropertyInfo[] propertys = t.GetType().GetProperties();
            foreach (PropertyInfo pi in propertys)
            {
                tempName = pi.Name;
                // 检查DataTable是否包含此列
                if (dt.Columns.Contains(tempName))
                {
                    // 判断此属性是否有Setter
                    if (!pi.CanRead) continue;
                    object value = dr[tempName];
                    if (value != DBNull.Value)
                        if (pi.PropertyType == typeof(int))
                        {
                            pi.SetValue(t, Convert.ToInt32(value), null);
                        }
                        else if (pi.PropertyType == typeof(string))
                        {
                            pi.SetValue(t, value.ToString(), null);
                        }
                        //pi.SetValue(t, value, null);
                }
            }
            ts.Add(t);
        }
        return ts;
        }

   
    }
}

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjgpxy.html