bootstrap mysql分页_bootstrap分页
使用bootstrap分頁插件,如下代碼是html代碼
分頁編號標題用戶
$(function () {
var str = "";
var carId = 1;
$.ajax({
url: "page.ashx",
data:{id:carId},
dataType: 'json',
type: 'post',
success: function (data) {
if (data != null) {
for (var i = 0; i < data.dt.length; i++) {
str += "
" + data.dt[i]["New_Id"] + "" + data.dt[i]["New_Title"] + "" + data.dt[i]["New_UserId"] + "";}
var pageCount = data.pageCount; //取到pageCount的值(把返回數(shù)據(jù)轉(zhuǎn)成object類型)
var currentPage = data.CurrentPage; //得到urrentPage
var element = $("#bp-3-element-test");
var options = {
bootstrapMajorVersion: 3,
currentPage: currentPage,
totalPages: pageCount,
numberOfPages: 5,
itemTexts: function (type, page, current) {
switch (type) {
case "first":
return "首頁";
case "prev":
return "上一頁";
case "next":
return "下一頁";
case "last":
return "末頁";
case "page":
return page;
}
}, onPageClicked: function (event, originalEvent, type, page) {
var str1 = "";
$("#tbody").html("");
$.ajax({
url: "page.ashx",
data: { id: page },
type: 'post',
success: function (data1) {
//console.log(data1);
if (data1 != null) {
var jsonobj = eval('(' + data1 + ')'); //將json字符串轉(zhuǎn)換成json數(shù)組
console.log(jsonobj.dt[0]["New_Id"]);
for (var i = 0; i < jsonobj.dt.length; i++) {
str1 += "
" + jsonobj.dt[i]["New_Id"] + "" + jsonobj.dt[i]["New_Title"] + "" + jsonobj.dt[i]["New_UserId"] + "";}
console.log(str1);
$("#tbody").html(str1);
}
}
})
}
}
element.bootstrapPaginator(options);
}
$("#tbody").html(str);
}
})
})
一般處理程序
context.Response.ContentType = "text/plain";
int id =Convert.ToInt32(context.Request["id"]);
const int pageSize = 5;
string sql = "select count(*) from news";
int rowCount =(int)SQLHelper.ExecuteSclar(sql);
if (rowCount % pageSize != 0)
{
rowCount = rowCount / pageSize + 1;
}
else
{
rowCount = rowCount / pageSize;
}
DataTable dt = GetListByPageByWhere("news", "*", "new_id", "", pageSize, id, rowCount);
var strResult = "{\"pageCount\":" + rowCount + ",\"CurrentPage\":" + id + ",\"dt\":" + JsonConvert.SerializeObject(dt) + "}";
context.Response.Write(strResult);
return;
}
private static DataTable GetListByPageByWhere(string tabname, string ReFieldsStr, string order, string strWhere, int PageSize, int PageIndex, int TotalRecord)
{
SqlParameter[] parameters = new SqlParameter[]{
new SqlParameter{ ParameterName="@TableName" ,SqlDbType=SqlDbType.VarChar,Value=tabname},
new SqlParameter{ParameterName="@ReFieldsStr",SqlDbType=SqlDbType.VarChar,Value=ReFieldsStr},
new SqlParameter{ParameterName="@OrderString",SqlDbType=SqlDbType.VarChar,Value=order},
new SqlParameter{ParameterName="@WhereString", SqlDbType=SqlDbType.VarChar, Value=strWhere},
new SqlParameter{ ParameterName="@PageSize", SqlDbType=SqlDbType.Int,Value=PageSize},
new SqlParameter{ParameterName="@PageIndex", SqlDbType=SqlDbType.Int,Value=PageIndex},
new SqlParameter{ParameterName="@TotalRecord",SqlDbType= SqlDbType.Int,Value=TotalRecord},
};
return SQLHelper.ExecuteDataTable("PROCE_PAGECHANGE", CommandType.StoredProcedure, parameters);
數(shù)據(jù)庫的分頁存儲過程
USE [ActivaOnlineSupport]
GO
/****** Object: StoredProcedure [dbo].[PROCE_PAGECHANGE] Script Date: 08/13/2014 13:45:17 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[PROCE_PAGECHANGE]
(
@TableName varchar(50), --表名
@ReFieldsStr varchar(200) = '*', --字段名(全部字段為*)
@OrderString varchar(200), --排序字段(必須!支持多字段不用加order by)
@WhereString varchar(500) =N'', --條件語句(不用加where)
@PageSize int, --每頁多少條記錄
@PageIndex int = 1 , --指定當前為第幾頁
@TotalRecord int output --返回總記錄數(shù)
)
AS
BEGIN
--處理開始點和結(jié)束點
Declare @StartRecord int;
Declare @EndRecord int;
Declare @TotalCountSql nvarchar(500);
Declare @SqlString nvarchar(2000);
set @StartRecord = (@PageIndex-1)*@PageSize + 1
set @EndRecord = @StartRecord + @PageSize - 1
SET @TotalCountSql= N'select @TotalRecord = count(*) from ' + @TableName;--總記錄數(shù)語句
SET @SqlString = N'(select row_number() over (order by '+ @OrderString +') as rowId,'+@ReFieldsStr+' from '+ @TableName;--查詢語句
--
IF (@WhereString! = '' or @WhereString!=null)
BEGIN
SET @TotalCountSql=@TotalCountSql + ' where '+ @WhereString;
SET @SqlString =@SqlString+ ' where '+ @WhereString;
END
--第一次執(zhí)行得到
--IF(@TotalRecord is null)
-- BEGIN
EXEC sp_executesql @totalCountSql,N'@TotalRecord int out',@TotalRecord output;--返回總記錄數(shù)
-- END
----執(zhí)行主語句
set @SqlString ='select * from ' + @SqlString + ') as t where rowId between ' + ltrim(str(@StartRecord)) + ' and ' + ltrim(str(@EndRecord));
Exec(@SqlString)
END
總結(jié)
以上是生活随笔為你收集整理的bootstrap mysql分页_bootstrap分页的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql 已存在数据_MySQL跳过已
- 下一篇: mysql查找字符串最后位置_mysql