C#.NET中最直接的高效分页方法
页面前端JS
function filldate(type, page, status) {//类型,页号,状态
$.post("showdata.ashx", { "par": type + ',' + page + "," + status }, function (data, status) {
if (data != "") {
var data1 = data.split(";");
$("#showdata").empty();
$("#showdata").html(data1[0].toString());
var va = parseInt(data1[1]);
var setv = "";
if (va > 0) {
for (var i = 0; i < va; i++) {
setv += "<option value='" + i + 1 + "'>第" + i + 1 + "页</option>";
}
}
$("#showpage").html(setv);
}
else {
$("#showdata").html("<tr><td>没有找到配匹数据<tr><td>");
}
});
}
页面前端DOM对象
<table id="showdata"></table>
一般处理程序showdata.ashx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Text;
namespace HXHotel.MoreReservation
{
/// <summary>
/// showdata 的摘要说明
/// </summary>
public class showdata : IHttpHandler
{
HXHotelBll.trent ht = new HXHotelBll.trent();
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
string condition = context.Request["par"];
string[]cons=condition.Split(',');
string gtype = "";
if (cons[0] == "餐厅")
{
gtype = "餐厅预订";
}
else if (cons[0] == "茶楼")
{
gtype = "茶楼预订";
}
int page = int.Parse(cons[1]);
DataTable sdt = ht.getdata("select * from(select *,(select COUNT(id) from guestbook where pro='" + gtype + "' and flag=" + cons[2] + ")maxid,ROW_NUMBER() over(Order by indate)rownum from guestbook where pro='" + gtype + "' and flag=" + cons[2] + ")t where t.rownum>"+(page-1)*10+" and t.rownum<="+page*10);
StringBuilder data1 = new StringBuilder();
if (sdt.Rows.Count > 0)
{
for (int i = 0; i < sdt.Rows.Count; i++)
{
data1.Append("<tr onclick=\"operate(" + sdt.Rows[i][0] + ",this,'" + sdt.Rows[i][13] + "')\"><td>" + sdt.Rows[i][1] + "</td><td>" + sdt.Rows[i][2] + "</td><td>" + sdt.Rows[i][5] + "</td><td>" + sdt.Rows[i][17] + "</td><td>" + sdt.Rows[i][6] + "</td></tr>");
}
data1.Append(";");
data1.Append(sdt.Rows[0][22]);
context.Response.Write(data1.ToString());
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
function filldate(type, page, status) {//类型,页号,状态
$.post("showdata.ashx", { "par": type + ',' + page + "," + status }, function (data, status) {
if (data != "") {
var data1 = data.split(";");
$("#showdata").empty();
$("#showdata").html(data1[0].toString());
var va = parseInt(data1[1]);
var setv = "";
if (va > 0) {
for (var i = 0; i < va; i++) {
setv += "<option value='" + i + 1 + "'>第" + i + 1 + "页</option>";
}
}
$("#showpage").html(setv);
}
else {
$("#showdata").html("<tr><td>没有找到配匹数据<tr><td>");
}
});
}
页面前端DOM对象
<table id="showdata"></table>
一般处理程序showdata.ashx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Text;
namespace HXHotel.MoreReservation
{
/// <summary>
/// showdata 的摘要说明
/// </summary>
public class showdata : IHttpHandler
{
HXHotelBll.trent ht = new HXHotelBll.trent();
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
string condition = context.Request["par"];
string[]cons=condition.Split(',');
string gtype = "";
if (cons[0] == "餐厅")
{
gtype = "餐厅预订";
}
else if (cons[0] == "茶楼")
{
gtype = "茶楼预订";
}
int page = int.Parse(cons[1]);
DataTable sdt = ht.getdata("select * from(select *,(select COUNT(id) from guestbook where pro='" + gtype + "' and flag=" + cons[2] + ")maxid,ROW_NUMBER() over(Order by indate)rownum from guestbook where pro='" + gtype + "' and flag=" + cons[2] + ")t where t.rownum>"+(page-1)*10+" and t.rownum<="+page*10);
StringBuilder data1 = new StringBuilder();
if (sdt.Rows.Count > 0)
{
for (int i = 0; i < sdt.Rows.Count; i++)
{
data1.Append("<tr onclick=\"operate(" + sdt.Rows[i][0] + ",this,'" + sdt.Rows[i][13] + "')\"><td>" + sdt.Rows[i][1] + "</td><td>" + sdt.Rows[i][2] + "</td><td>" + sdt.Rows[i][5] + "</td><td>" + sdt.Rows[i][17] + "</td><td>" + sdt.Rows[i][6] + "</td></tr>");
}
data1.Append(";");
data1.Append(sdt.Rows[0][22]);
context.Response.Write(data1.ToString());
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
}