借首页发布,使用存储过程,分页用户控件,jQuery进行Ajax分页,比较复杂,但方便扩展。提供了源码demo下载,提供了演示例子。代码有很多不完善的地方,希望各位提出。
效果图:http://www.ukei.cn/ob1.html
代码这里下载/Files/genson/AjaxPager.rar
l准备工作:
- jQuery,到http://www.jquery.com下载。
- 分页的存储过程 准备工作:http://www.cnblogs.com/genson/archive/2006/01/17/318882.html 这里可以找到。
- 分页用户控件,首先我们先写一个基类继承 UserControl,主要是分页的属性和一个静态方法,代码如下
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
using System.Text;
using System.Collections.Specialized;
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
/**//// <summary>
/// Summary description for UserControlBase
/// </summary>
public abstract class DataUserControlBase : UserControl
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
public int recordCount = 0;
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
public abstract void BindData();
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
protected override void OnLoad(EventArgs e)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
string p = Request.QueryString["p"];
if (!string.IsNullOrEmpty(p))
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
PageIndex = Convert.ToInt32(p);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
else
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
PageIndex = 1;
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
BindData();
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
if (!Page.ClientScript.IsClientScriptIncludeRegistered(typeof(Page), "PagerCheck"))
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Page.ClientScript.RegisterClientScriptInclude(typeof(Page), "PagerCheck", ResolveClientUrl("~/js/PagerCheck.js"));
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
base.OnLoad(e);
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
private object[] urlVariantParameters;
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 页面传递多个参数的时候使用,这个要跟UrlParamers替换的数组一致,当参数只有一个的时候,可以省略
/// </summary>
public object[] UrlVariantParameters
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return urlVariantParameters; }
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
set
{ urlVariantParameters = value; }
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
private string strWhere = string.Empty;
public string StrWhere
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
get
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return strWhere;
}
set
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
strWhere = value;
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
private bool orderType = true;
public bool OrderType
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return orderType; }
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
set
{ orderType = value; }
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
private string fldName = "DateCreated";
public string FldName
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return fldName; }
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
set
{ fldName = value; }
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
private int _recordCount;
public virtual int RecordCount
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
get
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return _recordCount;
}
set
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
_recordCount = value;
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
private int pageIndex = 1;
public virtual int PageIndex
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
get
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return pageIndex;
}
set
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
pageIndex = value;
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
public virtual int PageCount
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
get
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return RecordCount % PageSize == 0 ? RecordCount / PageSize : RecordCount / PageSize + 1;
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
private string urlParamers;
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 指通过页面传递参数的地址:如UrlParamers = "~/ob{0}.html";
/// </summary>
public virtual string UrlParamers
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
get
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return urlParamers;
}
set
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
urlParamers = value;
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
private int pageSize = 10;
public virtual int PageSize
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
get
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return pageSize;
}
set
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
pageSize = value;
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
private bool ajaxEnabled = true;
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 是否启用Ajax效果分页,默认启用
/// </summary>
public virtual bool AjaxEnabled
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
get
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return ajaxEnabled;
}
set
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
ajaxEnabled = value;
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
public static void SetProperty(DataUserControlBase pager, DataUserControlBase b)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
b.RecordCount = b.recordCount;
pager.RecordCount = b.RecordCount;
pager.PageSize = b.PageSize;
pager.PageIndex = b.PageIndex;
pager.UrlParamers = b.UrlParamers;
pager.AjaxEnabled = b.AjaxEnabled;
pager.UrlVariantParameters = b.UrlVariantParameters;
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
- 然后我们再新增一个ascx文件,叫Pager.ascx吧!继承上面定义的DataUserControlBase,代码如下。
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
<%
@ Control Language="C#" AutoEventWireup="true" CodeFile="Pager.ascx.cs" Inherits="UC_Pager" %>
<!--这里开始输出页码条-->
<DIV class="pagebar">
<asp:PlaceHolder runat=server ID=ph />
</DIV>
<!--这里结束页码的输出-->
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Obj.DAL;
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
public partial class UC_Pager : DataUserControlBase
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
protected void Page_Load(object sender, EventArgs e)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
GeneratePagerLink(ph);
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
public virtual void GeneratePagerLink(Control container)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
int max = PagerHelper.MaxPageIndex(PageIndex);
int min = PagerHelper.MinPageIndex(PageIndex);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
//if (string.IsNullOrEmpty(VirtualCurrentPageUrl))
//{
// throw new Exception("VirtualCurrentPageUrl is null");
//}
if (PageCount <= max) max = PageCount;
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
if (PageCount == 1) return;
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
if (min != 1) //Prev
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
HyperLink hyprev = new HyperLink();
hyprev.Text = "<< ";
if (UrlVariantParameters == null)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
hyprev.NavigateUrl = string.Format(UrlParamers, min - 1);
}
else
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
UrlVariantParameters[0] = min - 1;
hyprev.NavigateUrl = string.Format(UrlParamers, UrlVariantParameters);
}
ConvertAnchor(hyprev, min-1);
container.Controls.Add(hyprev);
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
for (int i = min; i <= max; i++)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
HyperLink hy = new HyperLink();
if (UrlVariantParameters == null)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
hy.NavigateUrl = string.Format(UrlParamers, i);
}
else
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
UrlVariantParameters[0] = i;
hy.NavigateUrl = string.Format(UrlParamers, UrlVariantParameters);
}
hy.Text = i.ToString();
if (PageIndex == i)
hy.NavigateUrl = string.Empty;
else
ConvertAnchor(hy, i);
container.Controls.Add(hy);
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
if (PageCount > max) //Next
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
HyperLink hynext = new HyperLink();
hynext.Text = " >>";
if (UrlVariantParameters == null)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
hynext.NavigateUrl = string.Format(UrlParamers, max + 1);
}
else
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
UrlVariantParameters[0] = max + 1;
hynext.NavigateUrl = string.Format(UrlParamers, UrlVariantParameters);
}
ConvertAnchor(hynext,max+1);
container.Controls.Add(hynext);
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
private void ConvertAnchor(HyperLink hy,int p)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (AjaxEnabled)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
hy.Attributes.Add("onclick", hy.NavigateUrl);
hy.NavigateUrl = "#" + hy.NavigateUrl;
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
public virtual Control Container
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
get
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return ph;
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
public override void BindData()
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
protected override void OnPreRender(EventArgs e)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (RecordCount == 0)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
//Container.Controls.Add(new LiteralControl("<p style=text-align:center;>没有数据</p>"));
}
base.OnPreRender(e);
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
当然,少不了分页帮助类PagerHelper,代码如下:这里使用了MicroSoft.Application.Data那个SqlHelper.cs文件
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;
namespace Obj.DAL
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// Summary description for PageHelper
/// </summary>
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**/
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 分页类PagerHelper 的摘要说明。
/// </summary>
public class PagerHelper
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
private string connectionString;
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 得到记录集的构造函数
/// </summary>
/// <param name="tblname"></param>
/// <param name="sortname"></param>
/// <param name="docount"></param>
/// <param name="connectionString"></param>
public PagerHelper(string tblname, string sortname, bool docount, string connectionString)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
this.tblName = tblname;
this.fldName = sortname;
this.connectionString = connectionString;
this.docount = docount;
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 所有参数都有
/// </summary>
/// <param name="tblname"></param>
/// <param name="docount"></param>
/// <param name="strGetFields"></param>
/// <param name="fldName"></param>
/// <param name="pagesize"></param>
/// <param name="pageindex"></param>
/// <param name="ordertype"></param>
/// <param name="strwhere"></param>
/// <param name="connectionString"></param>
public PagerHelper(string tblname, bool docount,
string strGetFields, string fldName, int pagesize,
int pageindex, bool ordertype, string strwhere, string connectionString
)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
this.tblName = tblname;
this.docount = docount;
this.strGetFields = strGetFields;
this.fldName = fldName;
this.pagesize = pagesize;
this.pageindex = pageindex;
this.ordertype = ordertype;
this.strwhere = strwhere;
this.connectionString = connectionString;
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//**/
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 得到记录集的构造函数
/// </summary>
/// <param name="tblname"></param>
/// <param name="strwhere"></param>
/// <param name="connectionString"></param>
public PagerHelper(string tblname, string strwhere, string connectionString)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
this.tblName = tblname;
this.strwhere = strwhere;
this.docount = true;
this.connectionString = connectionString;
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
private string tblName;
public string TblName
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return tblName; }
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
set
{ tblName = value; }
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
private string strGetFields = "*";
public string StrGetFields
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return strGetFields; }
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
set
{ strGetFields = value; }
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
private string fldName = string.Empty;
public string FldName
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return fldName; }
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
set
{ fldName = value; }
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
private int pagesize = 10;
public int PageSize
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return pagesize; }
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
set
{ pagesize = value; }
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
private int pageindex = 1;
public int PageIndex
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return pageindex; }
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
set
{ pageindex = value; }
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
private bool docount = false;
public bool DoCount
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return docount; }
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
set
{ docount = value; }
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
private bool ordertype = false;
public bool OrderType
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return ordertype; }
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
set
{ ordertype = value; }
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
private string strwhere = string.Empty;
public string StrWhere
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return strwhere; }
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
set
{ strwhere = value; }
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
public IDataReader GetDataReader()
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
if (this.docount)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
throw new ArgumentException("要返回记录集,DoCount属性一定为false");
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
// System.Web.HttpContext.Current.Response.Write(pageindex);
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
return SqlHelper.ExecuteReader(connectionString, CommandType.StoredProcedure, "Pagination",
new SqlParameter("@tblName", this.tblName),
new SqlParameter("@strGetFields", this.strGetFields),
new SqlParameter("@fldName", this.fldName),
new SqlParameter("@PageSize", this.pagesize),
new SqlParameter("@PageIndex", this.pageindex),
new SqlParameter("@doCount", this.docount),
new SqlParameter("@OrderType", this.ordertype),
new SqlParameter("@strWhere", this.strwhere)
);
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
public DataSet GetDataSet()
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (this.docount)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
throw new ArgumentException("要返回记录集,DoCount属性一定为false");
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
return SqlHelper.ExecuteDataset(connectionString, CommandType.StoredProcedure, "Pagination",
new SqlParameter("@tblName", this.tblName),
new SqlParameter("@strGetFields", this.strGetFields),
new SqlParameter("@fldName", this.fldName),
new SqlParameter("@PageSize", this.pagesize),
new SqlParameter("@PageIndex", this.pageindex),
new SqlParameter("@doCount", this.docount),
new SqlParameter("@OrderType", this.ordertype),
new SqlParameter("@strWhere", this.strwhere)
);
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
public int GetCount()
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (!this.docount)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
throw new ArgumentException("要返回总数统计,DoCount属性一定为true");
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
return (int)SqlHelper.ExecuteScalar(connectionString, CommandType.StoredProcedure, "Pagination",
new SqlParameter("@tblName", this.tblName),
new SqlParameter("@strGetFields", this.strGetFields),
new SqlParameter("@fldName", this.fldName),
new SqlParameter("@PageSize", this.pagesize),
new SqlParameter("@PageIndex", this.pageindex),
new SqlParameter("@doCount", this.docount),
new SqlParameter("@OrderType", this.ordertype),
new SqlParameter("@strWhere", this.strwhere)
);
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
public static int MaxPageIndex(int pageindex)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (pageindex < 10)
return 10;
string numstr = pageindex.ToString();
numstr = numstr.Substring(0, numstr.Length - 1);
return Convert.ToInt32(numstr + "0") + 10;
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
public static int MinPageIndex(int pageindex)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (pageindex < 10)
return 1;
string numstr = pageindex.ToString();
numstr = numstr.Substring(0, numstr.Length - 1);
return Convert.ToInt32(numstr + "0");
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
这一切准备好之后,我们就可以对数据进行分页程序开发了。 这篇文章也许写得不是很好,同样代码也有很多可以修改的地方,代码我已经测试过,兼容ie和ff2.0。如果有问题,欢迎回帖,也可以
发信息给我。