js:
var pageCount = 5; //每页显示最多页数
var pageNum = 0; //总页数
var currentPage = 1; //当前页
var startcount = 0;
var endcount = 0;
jQuery(function () {
jQuery.post("fordata.ashx", { "type": 0, "Action": "GetPageCount", "huodongid": huodongid }, function (data) {
pageNum = data;
GetPageData(currentPage);
});
});
//加载页数
function DisplayPage() {
var html = '';
html += "<a href='javascript:;' id='homePage'>首页</a><a href='javascript:;' id='prePage'>上一页</a>";
if (currentPage == 1 && pageNum >= pageCount) {
startcount = 1;
endcount = 5;
} else if (currentPage != 1 && pageNum >= pageCount) {
if (currentPage == startcount) {
if (currentPage - 2 <= 0) {
startcount = 1;
}
else {
startcount = currentPage - 2;
endcount = Number(currentPage) + 2;
}
if (endcount <= pageCount) {
endcount = pageCount;
}
if (Number(currentPage) + 2 >= pageNum) {
endcount = pageNum;
}
}
if (currentPage == endcount) {
if (currentPage - 2 <= 0) {
startcount = 1;
}
else {
startcount = currentPage - 2;
endcount = Number(currentPage) + 2;
}
if (endcount <= pageCount) {
endcount = pageCount;
}
if (Number(currentPage) + 2 >= pageNum) {
endcount = pageNum;
}
}
}
else {
startcount = 1;
endcount = pageNum;
}
for (var i = startcount; i <= endcount; i++) {
html += "<a href='javascript:;' name='page_a'>" + i + "</a>";
}
html += "<a href='javascript:;' id='nextPage'>下一页</a><a href='javascript:;' id='lastPage'>末页</a>";
jQuery('#pagenumLabel').html(html);
//首页
jQuery('#homePage').click(function () {
GetPageData(1);
});
//上一页
jQuery('#prePage').click(function () {
var pageIndex = currentPage - 1;
if (pageIndex <= 0) {
pageIndex = 1;
currentPage = 1;
}
GetPageData(pageIndex);
});
//下一页
jQuery('#nextPage').click(function () {
var pageIndex = currentPage + 1;
if (pageIndex >= pageNum) {
pageIndex = pageNum;
currentPage = pageNum;
}
GetPageData(pageIndex);
});
jQuery('#lastPage').click(function () {
GetPageData(pageNum);
});
//点击页数时加载该页对应数据
jQuery('a[name="page_a"]').click(function () {
GetPageData(jQuery(this).text());
});
}
//加载每页内容
function GetPageData(pageIndex) {
currentPage = pageIndex;
DisplayPage();
jQuery.getJSON("fordata.ashx", { "type": 0, "huodongid": huodongid, "Action": "GetPageData", "PageNum": currentPage, "top": 60, "left": 600 }, function (data) {
var html = '';
jQuery(data).each(function (i, model) {
html += "<div class='xy' id='bid_" + model.id + "' style='position: absolute;margin-left:" + model.left + "px;margin-top:" + model.top + "px;'><div class='close_a'><a href='javascript:;' name='close' check='" + model.id + "'>x</a></div><h5>" + model.title + "</h5><p>" + model.content + "</p></div>";
});
jQuery('#ulCategory').html(html);
jQuery('a[name="close"]').click(function () {
jQuery('#bid_' + jQuery(this).attr('check') + '').hide();
});
if (html.length > 0) {
jQuery('.xy').draggable();
jQuery(".xy").mousedown(function () {
jQuery('.xy').css("z-index", "1");
jQuery(this).css("z-index", "2");
});
jQuery(".xy").mouseup(function () {
jQuery(this).droppable();
});
}
});
}
一般处理程序:
int pageDisCount = 50;//每页多少条数据
string strAction = context.Request.Params["Action"];
//取页数
if(strAction == "GetPageCount")
{
string strSQL = "select COUNT(1) from tbl_vowwall where type=@huodongid";
SDN.DB.DAO.ParameterBox pb = new SDN.DB.DAO.ParameterBox("@huodongid",huodongid);
int intRecordCount = Convert.ToInt32(SDN.DB.DAO.SqlHelper.ExecuteScalar(strSQL,pb));//SqlHelper.ExecuteScalar(strSQL);
int intPageCount = intRecordCount / pageDisCount;
if(intRecordCount % pageDisCount != 0)
{
intPageCount++;
}
context.Response.Write(intPageCount);
}//取每页数据
else if(strAction == "GetPageData")
{
int top = string.IsNullOrEmpty(context.Request.Params["top"]) ? 260 : Convert.ToInt32(context.Request.Params["top"]);
int left = string.IsNullOrEmpty(context.Request.Params["left"]) ? 700 : Convert.ToInt32(context.Request.Params["left"]);
int intPageNum = Convert.ToInt32(context.Request.Params["PageNum"]);
string sql = "select top " + pageDisCount + " id,title,content,''as [top],'' as [left] from tbl_vowwall where type=@huodongid and id not in (select top (" + pageDisCount + "*(" + intPageNum + "-1)) id from tbl_vowwall where type=@huodongid order by id desc) order by id desc";
SDN.DB.DAO.ParameterBox pb = new SDN.DB.DAO.ParameterBox("@huodongid",huodongid);
SDN.Common.VO.DataObjectList datas = SDN.Common.VO.DataLoader.LoaderDataObjectListBySql(sql,pb);
SDN.Common.VO.DataObjectList list = new SDN.Common.VO.DataObjectList();
Random r = new Random();
foreach(SDN.Common.VO.DataObject obj in datas)
{
obj["id"] = obj["id"];
obj["content"] = obj["content"];
obj["title"] = obj["title"];
obj["top"] = r.Next(top);
obj["left"] = r.Next(left);
list.Add(obj);
}
context.Response.Write(list.GetJSON());
context.Response.End();
}