jQuery+存储过程实现无刷新分页(九)
jQuery+存储过程实现无刷新分页(九)
涉及到得知识点:
1.分页存储过程
2.分页原理
3.jQuery DOM操作
4.jQuery Ajax存取数据
效果图:
思路:数据库---DAL----BLL----UI
具体代码:
set ANSI_NULLS ONset QUOTED_IDENTIFIER ONgoCREATE PROCEDURE [dbo].[GetDataByPager]( @startIndex INT,--代表起始条数(从0开始) @tableName VARCHAR(50),--代表分页的表名称 @pageSize INT=5,--代表每页的条数 @condition VARCHAR(1000)='1=1',--代表条件 @key VARCHAR(20)='id', --代表主键 @orderType VARCHAR(20)='desc' --代表排序方式)ASBEGIN DECLARE @SQL VARCHAR(1000) SET @SQL='select TOP ' +CONVERT(VARCHAR(20),@pagesize)+' * FROM '+@tableName +' WHERE '+ @condition+' and '+@key+' NOT IN(SELECT TOP ' +CONVERT(VARCHAR(20),@startIndex)+' '+@key+' FROM '+@tableName+' where '+@condition+' order by '+@key+' '+@orderType+') order by '+@key+' '+@orderType EXEC(@SQL)END
set ANSI_NULLS ONset QUOTED_IDENTIFIER ONgo--得到要分页的表的总记录数CREATE PROCEDURE [dbo].[GetDataByPager_Count]( @tableName VARCHAR(200), @condition VARCHAR(1000)='1=1')ASBEGIN DECLARE @strsql VARCHAR(2000) SET @strsql = 'select count(*) from '+@tableName+' where '+@condition EXEC(@strsql)END
DAL层:
public static partial class AuthorService { ///
BLL层代码:
public static partial class AuthorManager { ///
引用了两个常用的js 代码:
String.format = function() { if (arguments.length == 0) return null; var str = arguments[0]; for (var i = 1; i < arguments.length; i++) { var re = new RegExp('\\{' + (i - 1) + '\\}', 'gm'); str = str.replace(re, arguments[i]); } return str;}
function StringBuffer(){ this._strings_=new Array();}StringBuffer.prototype.append = function(str){ this._strings_.push(str);}StringBuffer.prototype.toString=function(){ return this._strings_.join("");}
UI层得到数据:
public partial class HandleAuthorList : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { if (Request["startIndex"] != null && Request["limit"] != null) { int startIndex = int.Parse(Request["startIndex"].ToString()); int limit = int.Parse(Request["limit"].ToString()); IList
Ajax异步刷新:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="AuthorMgr.aspx.cs" Inherits="AuthorMgr" %>