.aspx
<script src="js/jquery.pagebar_min.js" type="text/javascript"></script>
<script type="text/javascript">
//換頁
$(function () {
changPage(1);
});
var total = 100;
function page(idx) {
var pagebar_arg = {
firstPageText: "<span class=\"gr12\"> 第一頁</span>", //"第一頁",
previousPageText: "<span class=\"gr12\"> 上一頁</span>", //"上一頁",
nextPageText: "<span class=\"gr12\"> 下一頁› </span>", //"下一頁",
lastPageText: "<span class=\"gr12\"> 最末頁››</span>" //"最末頁"
};
$("#pager").fadeIn().showPageBarPlus(total, <%= pageShowNum %>, idx, changPage, pagebar_arg);
}
function changPage(idx) {
data = {
pageShowNum: <%= pageShowNum %>,
nodeId: <%= nodeId %>,
index: idx
};
$.ajax({
async: false,
type: 'post',
url: 'PageList.ashx',
data: data,
dataType: 'text',
success: function (s1) {
//alert(s1);
if(s1.split("<%= sign %>").length >= 2){
$("#list").fadeIn().html(s1.split("<%= sign %>")[0]);
total = s1.split("<%= sign %>")[1];
//$("#totalNum").text(total);
}
}
});
page(idx);
}
</script>
<body>
<div id='list'></div>
<div id='pager'></div>
</body>
PageList.ashx
public void ProcessRequest (HttpContext context) {
int pageShowNum = Int32.Parse(context.Request.Form["pageShowNum"]);
int index = Int32.Parse(context.Request.Form["index"]);
//int selectNodeTreeId = Int32.Parse(context.Request.Form["nodeTreeId"]);
int nodeId = Int32.Parse(context.Request.Form["nodeId"]);
StringBuilder sb = new StringBuilder();
DBManger DBManger = new DBManger();
DataSet ds = DBManger.GetPage(index, pageShowNum, "user");
//取得db資料
DataTable dt = ds.Tables[1]; //搜出的資料
int totalPage = (int)ds.Tables[0].Rows[0]["total"];
sb.Append("<table>");
//加入colume 名稱
sb.Append("<tr class='White_box'>");
for (int i = 0; i < dt.Columns.Count; i++)
{
sb.Append("<th width=\"6%\">" + dt.Columns[i].ToString() + " </th>");
}
sb.Append("</tr>");
//加入內容
for (int i = 0; i < dt.Rows.Count; i++)
{
sb.Append("<tr class=\"White_box\">");
for (int j = 0; j < dt.Columns.Count; j++)
{
sb.Append("<td>" + dt.Rows[i][j].ToString() + "</td>");
}
sb.Append("</tr>");
}
sb.Append("</table>");
string htmlStr = "";
htmlStr = sb.ToString() + sign + totalPage;
context.Response.ContentType = "text/plain";
context.Response.Write(htmlStr);
}
標籤: C#, Jquery