使用存储过程,分页用户控件,jQuery进行Ajax分页!

效果图:http://www.ukei.cn/ob1.html
代码这里下载/Files/genson/AjaxPager.rar
l准备工作:

  1. jQuery,到http://www.jquery.com下载。
  2. 分页的存储过程 准备工作:http://www.cnblogs.com/genson/archive/2006/01/17/318882.html这里可以找到。
  3. 分页用户控件,首先我们先写一个基类继承 UserControl,主要是分页的属性和一个静态方法,代码如下
    None.gif using System;
    None.gif
    using System.Data;
    None.gif
    using System.Configuration;
    None.gif
    using System.Web;
    None.gif
    using System.Web.Security;
    None.gif
    using System.Web.UI;
    None.gif
    using System.Web.UI.WebControls;
    None.gif
    using System.Web.UI.WebControls.WebParts;
    None.gif
    using System.Web.UI.HtmlControls;
    None.gif
    using System.Collections;
    None.gif
    using System.Text;
    None.gif
    using System.Collections.Specialized;
    None.gif
    None.gif
    ExpandedBlockStart.gifContractedBlock.gif
    /**/ ///<summary>
    InBlock.gif
    ///SummarydescriptionforUserControlBase
    ExpandedBlockEnd.gif
    ///</summary>

    None.gif public abstract class DataUserControlBase:UserControl
    ExpandedBlockStart.gifContractedBlock.gif
    dot.gif {
    InBlock.gif
    publicintrecordCount=0;
    InBlock.gif
    InBlock.gif
    InBlock.gif
    publicabstractvoidBindData();
    InBlock.gif
    InBlock.gif
    protectedoverridevoidOnLoad(EventArgse)
    ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{
    InBlock.gif
    InBlock.gif
    stringp=Request.QueryString["p"];
    InBlock.gif
    if(!string.IsNullOrEmpty(p))
    ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{
    InBlock.gifPageIndex
    =Convert.ToInt32(p);
    InBlock.gif
    ExpandedSubBlockEnd.gif}

    InBlock.gif
    else
    ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{
    InBlock.gifPageIndex
    =1;
    InBlock.gif
    ExpandedSubBlockEnd.gif}

    InBlock.gif
    InBlock.gifBindData();
    InBlock.gif
    InBlock.gif
    if(!Page.ClientScript.IsClientScriptIncludeRegistered(typeof(Page),"PagerCheck"))
    ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{
    InBlock.gifPage.ClientScript.RegisterClientScriptInclude(
    typeof(Page),"PagerCheck",ResolveClientUrl("~/js/PagerCheck.js"));
    ExpandedSubBlockEnd.gif}

    InBlock.gif
    InBlock.gif
    base.OnLoad(e);
    ExpandedSubBlockEnd.gif}

    InBlock.gif
    InBlock.gif
    InBlock.gif
    InBlock.gif
    privateobject[]urlVariantParameters;
    ExpandedSubBlockStart.gifContractedSubBlock.gif
    /**////<summary>
    InBlock.gif
    ///页面传递多个参数的时候使用,这个要跟UrlParamers替换的数组一致,当参数只有一个的时候,可以省略
    ExpandedSubBlockEnd.gif
    ///</summary>

    InBlock.gifpublicobject[]UrlVariantParameters
    ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{
    ExpandedSubBlockStart.gifContractedSubBlock.gif
    getdot.gif{returnurlVariantParameters;}
    ExpandedSubBlockStart.gifContractedSubBlock.gif
    setdot.gif{urlVariantParameters=value;}
    ExpandedSubBlockEnd.gif}

    InBlock.gif
    InBlock.gif
    privatestringstrWhere=string.Empty;
    InBlock.gif
    publicstringStrWhere
    ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{
    InBlock.gif
    get
    ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{
    InBlock.gif
    returnstrWhere;
    ExpandedSubBlockEnd.gif}

    InBlock.gif
    set
    ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{
    InBlock.gifstrWhere
    =value;
    ExpandedSubBlockEnd.gif}

    ExpandedSubBlockEnd.gif}

    InBlock.gif
    InBlock.gif
    privateboolorderType=true;
    InBlock.gif
    publicboolOrderType
    ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{
    ExpandedSubBlockStart.gifContractedSubBlock.gif
    getdot.gif{returnorderType;}
    ExpandedSubBlockStart.gifContractedSubBlock.gif
    setdot.gif{orderType=value;}
    ExpandedSubBlockEnd.gif}

    InBlock.gif
    InBlock.gif
    privatestringfldName="DateCreated";
    InBlock.gif
    publicstringFldName
    ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{
    ExpandedSubBlockStart.gifContractedSubBlock.gif
    getdot.gif{returnfldName;}
    ExpandedSubBlockStart.gifContractedSubBlock.gif
    setdot.gif{fldName=value;}
    ExpandedSubBlockEnd.gif}

    InBlock.gif
    InBlock.gif
    privateint_recordCount;
    InBlock.gif
    publicvirtualintRecordCount
    ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{
    InBlock.gif
    get
    ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{
    InBlock.gif
    return_recordCount;
    ExpandedSubBlockEnd.gif}

    InBlock.gif
    set
    ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{
    InBlock.gif_recordCount
    =value;
    ExpandedSubBlockEnd.gif}

    ExpandedSubBlockEnd.gif}

    InBlock.gif
    InBlock.gif
    InBlock.gif
    privateintpageIndex=1;
    InBlock.gif
    publicvirtualintPageIndex
    ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{
    InBlock.gif
    get
    ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{
    InBlock.gif
    returnpageIndex;
    ExpandedSubBlockEnd.gif}

    InBlock.gif
    set
    ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{
    InBlock.gifpageIndex
    =value;
    ExpandedSubBlockEnd.gif}

    ExpandedSubBlockEnd.gif}

    InBlock.gif
    InBlock.gif
    InBlock.gif
    InBlock.gif
    publicvirtualintPageCount
    ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{
    InBlock.gif
    get
    ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{
    InBlock.gif
    returnRecordCount%PageSize==0?RecordCount/PageSize:RecordCount/PageSize+1;
    ExpandedSubBlockEnd.gif}

    ExpandedSubBlockEnd.gif}

    InBlock.gif
    InBlock.gif
    InBlock.gif
    privatestringurlParamers;
    ExpandedSubBlockStart.gifContractedSubBlock.gif
    /**////<summary>
    InBlock.gif
    ///指通过页面传递参数的地址:如UrlParamers="~/ob{0}.html";
    ExpandedSubBlockEnd.gif
    ///</summary>

    InBlock.gifpublicvirtualstringUrlParamers
    ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{
    InBlock.gif
    get
    ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{
    InBlock.gif
    returnurlParamers;
    ExpandedSubBlockEnd.gif}

    InBlock.gif
    set
    ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{
    InBlock.gifurlParamers
    =value;
    ExpandedSubBlockEnd.gif}

    ExpandedSubBlockEnd.gif}

    InBlock.gif
    InBlock.gif
    InBlock.gif
    privateintpageSize=10;
    InBlock.gif
    publicvirtualintPageSize
    ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{
    InBlock.gif
    get
    ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{
    InBlock.gif
    returnpageSize;
    ExpandedSubBlockEnd.gif}

    InBlock.gif
    set
    ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{
    InBlock.gifpageSize
    =value;
    ExpandedSubBlockEnd.gif}

    ExpandedSubBlockEnd.gif}

    InBlock.gif
    InBlock.gif
    privateboolajaxEnabled=true;
    ExpandedSubBlockStart.gifContractedSubBlock.gif
    /**////<summary>
    InBlock.gif
    ///是否启用Ajax效果分页,默认启用
    ExpandedSubBlockEnd.gif
    ///</summary>

    InBlock.gifpublicvirtualboolAjaxEnabled
    ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{
    InBlock.gif
    get
    ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{
    InBlock.gif
    returnajaxEnabled;
    ExpandedSubBlockEnd.gif}

    InBlock.gif
    set
    ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{
    InBlock.gifajaxEnabled
    =value;
    ExpandedSubBlockEnd.gif}

    ExpandedSubBlockEnd.gif}

    InBlock.gif
    InBlock.gif
    InBlock.gif
    publicstaticvoidSetProperty(DataUserControlBasepager,DataUserControlBaseb)
    ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{
    InBlock.gifb.RecordCount
    =b.recordCount;
    InBlock.gifpager.RecordCount
    =b.RecordCount;
    InBlock.gifpager.PageSize
    =b.PageSize;
    InBlock.gifpager.PageIndex
    =b.PageIndex;
    InBlock.gifpager.UrlParamers
    =b.UrlParamers;
    InBlock.gifpager.AjaxEnabled
    =b.AjaxEnabled;
    InBlock.gifpager.UrlVariantParameters
    =b.UrlVariantParameters;
    ExpandedSubBlockEnd.gif}

    InBlock.gif
    InBlock.gif
    InBlock.gif
    InBlock.gif
    ExpandedBlockEnd.gif}

    None.gif
  4. 然后我们再新增一个ascx文件,叫Pager.ascx吧!继承上面定义的DataUserControlBase,代码如下。
    ExpandedBlockStart.gif ContractedBlock.gif <% dot.gif @ControlLanguage="C#"AutoEventWireup="true"CodeFile="Pager.ascx.cs"Inherits="UC_Pager" %>
    None.gif
    <!-- 这里开始输出页码条 -->
    None.gif
    < DIV class ="pagebar" >
    None.gif
    < asp:PlaceHolder runat =server ID =ph />
    None.gif
    </ DIV >
    None.gif
    <!-- 这里结束页码的输出 -->
    None.gif
    None.gif
    None.gif
    None.gif
    ContractedBlock.gif ExpandedBlockStart.gif
    <!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->None.gifusingSystem;
    None.gif
    usingSystem.Data;
    None.gif
    usingSystem.Configuration;
    None.gif
    usingSystem.Collections;
    None.gif
    usingSystem.Web;
    None.gif
    usingSystem.Web.Security;
    None.gif
    usingSystem.Web.UI;
    None.gif
    usingSystem.Web.UI.WebControls;
    None.gif
    usingSystem.Web.UI.WebControls.WebParts;
    None.gif
    usingSystem.Web.UI.HtmlControls;
    None.gif
    usingObj.DAL;
    None.gif
    None.gif
    publicpartialclassUC_Pager:DataUserControlBase
    ExpandedBlockStart.gifContractedBlock.gif
    dot.gif{
    InBlock.gif
    protectedvoidPage_Load(objectsender,EventArgse)
    ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{
    InBlock.gifGeneratePagerLink(ph);
    InBlock.gif
    ExpandedSubBlockEnd.gif}

    InBlock.gif
    InBlock.gif
    InBlock.gif
    InBlock.gif
    InBlock.gif
    publicvirtualvoidGeneratePagerLink(Controlcontainer)
    ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{
    InBlock.gif
    InBlock.gif
    intmax=PagerHelper.MaxPageIndex(PageIndex);
    InBlock.gif
    intmin=PagerHelper.MinPageIndex(PageIndex);
    InBlock.gif
    InBlock.gif
    //if(string.IsNullOrEmpty(VirtualCurrentPageUrl))
    InBlock.gif
    //{
    InBlock.gif
    //thrownewException("VirtualCurrentPageUrlisnull");
    InBlock.gif
    //}
    InBlock.gif
    if(PageCount<=max)max=PageCount;
    InBlock.gif
    InBlock.gif
    if(PageCount==1)return;
    InBlock.gif
    InBlock.gif
    InBlock.gif
    if(min!=1)//Prev
    ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{
    InBlock.gifHyperLinkhyprev
    =newHyperLink();
    InBlock.gifhyprev.Text
    ="&lt;&lt;";
    InBlock.gif
    if(UrlVariantParameters==null)
    ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{
    InBlock.gifhyprev.NavigateUrl
    =string.Format(UrlParamers,min-1);
    InBlock.gif
    ExpandedSubBlockEnd.gif}

    InBlock.gif
    else
    ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{
    InBlock.gifUrlVariantParameters[
    0]=min-1;
    InBlock.gifhyprev.NavigateUrl
    =string.Format(UrlParamers,UrlVariantParameters);
    ExpandedSubBlockEnd.gif}

    InBlock.gifConvertAnchor(hyprev,min
    -1);
    InBlock.gifcontainer.Controls.Add(hyprev);
    ExpandedSubBlockEnd.gif}

    InBlock.gif
    InBlock.gif
    for(inti=min;i<=max;i++)
    ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{
    InBlock.gifHyperLinkhy
    =newHyperLink();
    InBlock.gif
    if(UrlVariantParameters==null)
    ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{
    InBlock.gifhy.NavigateUrl
    =string.Format(UrlParamers,i);
    ExpandedSubBlockEnd.gif}

    InBlock.gif
    else
    ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{
    InBlock.gifUrlVariantParameters[
    0]=i;
    InBlock.gifhy.NavigateUrl
    =string.Format(UrlParamers,UrlVariantParameters);
    ExpandedSubBlockEnd.gif}

    InBlock.gifhy.Text
    =i.ToString();
    InBlock.gif
    if(PageIndex==i)
    InBlock.gifhy.NavigateUrl
    =string.Empty;
    InBlock.gif
    else
    InBlock.gifConvertAnchor(hy,i);
    InBlock.gif
    InBlock.gifcontainer.Controls.Add(hy);
    InBlock.gif
    InBlock.gif
    ExpandedSubBlockEnd.gif}

    InBlock.gif
    InBlock.gif
    if(PageCount>max)//Next
    ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{
    InBlock.gifHyperLinkhynext
    =newHyperLink();
    InBlock.gifhynext.Text
    ="&gt;&gt;";
    InBlock.gif
    if(UrlVariantParameters==null)
    ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{
    InBlock.gifhynext.NavigateUrl
    =string.Format(UrlParamers,max+1);
    ExpandedSubBlockEnd.gif}

    InBlock.gif
    else
    ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{
    InBlock.gifUrlVariantParameters[
    0]=max+1;
    InBlock.gifhynext.NavigateUrl
    =string.Format(UrlParamers,UrlVariantParameters);
    ExpandedSubBlockEnd.gif}

    InBlock.gifConvertAnchor(hynext,max
    +1);
    InBlock.gifcontainer.Controls.Add(hynext);
    ExpandedSubBlockEnd.gif}

    ExpandedSubBlockEnd.gif}

    InBlock.gif
    InBlock.gif
    InBlock.gif
    InBlock.gif
    privatevoidConvertAnchor(HyperLinkhy,intp)
    ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{
    InBlock.gif
    if(AjaxEnabled)
    ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{
    InBlock.gifhy.Attributes.Add(
    "onclick",hy.NavigateUrl);
    InBlock.gifhy.NavigateUrl
    ="#"+hy.NavigateUrl;
    ExpandedSubBlockEnd.gif}

    InBlock.gif
    ExpandedSubBlockEnd.gif}

    InBlock.gif
    InBlock.gif
    InBlock.gif
    publicvirtualControlContainer
    ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{
    InBlock.gif
    get
    ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{
    InBlock.gif
    returnph;
    ExpandedSubBlockEnd.gif}

    InBlock.gif
    ExpandedSubBlockEnd.gif}

    InBlock.gif
    InBlock.gif
    InBlock.gif
    InBlock.gif
    publicoverridevoidBindData()
    ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{
    InBlock.gif
    ExpandedSubBlockEnd.gif}

    InBlock.gif
    InBlock.gif
    protectedoverridevoidOnPreRender(EventArgse)
    ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{
    InBlock.gif
    if(RecordCount==0)
    ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{
    InBlock.gif
    //Container.Controls.Add(newLiteralControl("<pstyle=text-align:center;>没有数据</p>"));
    ExpandedSubBlockEnd.gif
    }

    InBlock.gif
    base.OnPreRender(e);
    ExpandedSubBlockEnd.gif}

    ExpandedBlockEnd.gif}

    None.gif
当然,少不了分页帮助类PagerHelper,代码如下:这里使用了MicroSoft.Application.Data那个SqlHelper.cs文件
ContractedBlock.gif ExpandedBlockStart.gif
<!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>-->None.gifusingSystem;
None.gif
usingSystem.Data;
None.gif
usingSystem.Configuration;
None.gif
usingSystem.Web;
None.gif
usingSystem.Web.Security;
None.gif
usingSystem.Web.UI;
None.gif
usingSystem.Web.UI.WebControls;
None.gif
usingSystem.Web.UI.WebControls.WebParts;
None.gif
usingSystem.Web.UI.HtmlControls;
None.gif
usingSystem.Data.SqlClient;
None.gif
usingMicrosoft.ApplicationBlocks.Data;
None.gif
namespaceObj.DAL
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif
/**////<summary>
InBlock.gif
///SummarydescriptionforPageHelper
ExpandedSubBlockEnd.gif
///</summary>

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif
/**////<summary>
InBlock.gif
///分页类PagerHelper的摘要说明。
ExpandedSubBlockEnd.gif
///</summary>

InBlock.gifpublicclassPagerHelper
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
privatestringconnectionString;
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif
/**////<summary>
InBlock.gif
///得到记录集的构造函数
InBlock.gif
///</summary>
InBlock.gif
///<paramname="tblname"></param>
InBlock.gif
///<paramname="sortname"></param>
InBlock.gif
///<paramname="docount"></param>
ExpandedSubBlockEnd.gif
///<paramname="connectionString"></param>

InBlock.gifpublicPagerHelper(stringtblname,stringsortname,booldocount,stringconnectionString)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
this.tblName=tblname;
InBlock.gif
this.fldName=sortname;
InBlock.gif
this.connectionString=connectionString;
InBlock.gif
this.docount=docount;
ExpandedSubBlockEnd.gif}

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif
/**////<summary>
InBlock.gif
///所有参数都有
InBlock.gif
///</summary>
InBlock.gif
///<paramname="tblname"></param>
InBlock.gif
///<paramname="docount"></param>
InBlock.gif
///<paramname="strGetFields"></param>
InBlock.gif
///<paramname="fldName"></param>
InBlock.gif
///<paramname="pagesize"></param>
InBlock.gif
///<paramname="pageindex"></param>
InBlock.gif
///<paramname="ordertype"></param>
InBlock.gif
///<paramname="strwhere"></param>
ExpandedSubBlockEnd.gif
///<paramname="connectionString"></param>

InBlock.gifpublicPagerHelper(stringtblname,booldocount,
InBlock.gif
stringstrGetFields,stringfldName,intpagesize,
InBlock.gif
intpageindex,boolordertype,stringstrwhere,stringconnectionString
InBlock.gif)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
this.tblName=tblname;
InBlock.gif
this.docount=docount;
InBlock.gif
this.strGetFields=strGetFields;
InBlock.gif
this.fldName=fldName;
InBlock.gif
this.pagesize=pagesize;
InBlock.gif
this.pageindex=pageindex;
InBlock.gif
this.ordertype=ordertype;
InBlock.gif
this.strwhere=strwhere;
InBlock.gif
this.connectionString=connectionString;
InBlock.gif
InBlock.gif
ExpandedSubBlockEnd.gif}

InBlock.gif
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif
/**//**/
ExpandedSubBlockStart.gifContractedSubBlock.gif
/**////<summary>
InBlock.gif
///得到记录集的构造函数
InBlock.gif
///</summary>
InBlock.gif
///<paramname="tblname"></param>
InBlock.gif
///<paramname="strwhere"></param>
ExpandedSubBlockEnd.gif
///<paramname="connectionString"></param>

InBlock.gifpublicPagerHelper(stringtblname,stringstrwhere,stringconnectionString)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
this.tblName=tblname;
InBlock.gif
this.strwhere=strwhere;
InBlock.gif
this.docount=true;
InBlock.gif
this.connectionString=connectionString;
ExpandedSubBlockEnd.gif}

InBlock.gif
InBlock.gif
privatestringtblName;
InBlock.gif
publicstringTblName
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif
getdot.gif{returntblName;}
ExpandedSubBlockStart.gifContractedSubBlock.gif
setdot.gif{tblName=value;}
ExpandedSubBlockEnd.gif}

InBlock.gif
InBlock.gif
privatestringstrGetFields="*";
InBlock.gif
publicstringStrGetFields
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif
getdot.gif{returnstrGetFields;}
ExpandedSubBlockStart.gifContractedSubBlock.gif
setdot.gif{strGetFields=value;}
ExpandedSubBlockEnd.gif}

InBlock.gif
InBlock.gif
privatestringfldName=string.Empty;
InBlock.gif
publicstringFldName
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif
getdot.gif{returnfldName;}
ExpandedSubBlockStart.gifContractedSubBlock.gif
setdot.gif{fldName=value;}
ExpandedSubBlockEnd.gif}

InBlock.gif
InBlock.gif
InBlock.gif
InBlock.gif
privateintpagesize=10;
InBlock.gif
publicintPageSize
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif
getdot.gif{returnpagesize;}
ExpandedSubBlockStart.gifContractedSubBlock.gif
setdot.gif{pagesize=value;}
ExpandedSubBlockEnd.gif}

InBlock.gif
InBlock.gif
privateintpageindex=1;
InBlock.gif
publicintPageIndex
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif
getdot.gif{returnpageindex;}
ExpandedSubBlockStart.gifContractedSubBlock.gif
setdot.gif{pageindex=value;}
ExpandedSubBlockEnd.gif}

InBlock.gif
InBlock.gif
InBlock.gif
privatebooldocount=false;
InBlock.gif
publicboolDoCount
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif
getdot.gif{returndocount;}
ExpandedSubBlockStart.gifContractedSubBlock.gif
setdot.gif{docount=value;}
ExpandedSubBlockEnd.gif}

InBlock.gif
InBlock.gif
privateboolordertype=false;
InBlock.gif
publicboolOrderType
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif
getdot.gif{returnordertype;}
ExpandedSubBlockStart.gifContractedSubBlock.gif
setdot.gif{ordertype=value;}
ExpandedSubBlockEnd.gif}

InBlock.gif
InBlock.gif
privatestringstrwhere=string.Empty;
InBlock.gif
publicstringStrWhere
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif
getdot.gif{returnstrwhere;}
ExpandedSubBlockStart.gifContractedSubBlock.gif
setdot.gif{strwhere=value;}
ExpandedSubBlockEnd.gif}

InBlock.gif
InBlock.gif
InBlock.gif
InBlock.gif
InBlock.gif
InBlock.gif
InBlock.gif
publicIDataReaderGetDataReader()
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
InBlock.gif
if(this.docount)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
thrownewArgumentException("要返回记录集,DoCount属性一定为false");
ExpandedSubBlockEnd.gif}

InBlock.gif
InBlock.gif
InBlock.gif
InBlock.gif
//System.Web.HttpContext.Current.Response.Write(pageindex);
InBlock.gif

InBlock.gif
returnSqlHelper.ExecuteReader(connectionString,CommandType.StoredProcedure,"Pagination",
InBlock.gif
newSqlParameter("@tblName",this.tblName),
InBlock.gif
newSqlParameter("@strGetFields",this.strGetFields),
InBlock.gif
newSqlParameter("@fldName",this.fldName),
InBlock.gif
newSqlParameter("@PageSize",this.pagesize),
InBlock.gif
newSqlParameter("@PageIndex",this.pageindex),
InBlock.gif
newSqlParameter("@doCount",this.docount),
InBlock.gif
newSqlParameter("@OrderType",this.ordertype),
InBlock.gif
newSqlParameter("@strWhere",this.strwhere)
InBlock.gif);
ExpandedSubBlockEnd.gif}

InBlock.gif
InBlock.gif
publicDataSetGetDataSet()
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
if(this.docount)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
thrownewArgumentException("要返回记录集,DoCount属性一定为false");
ExpandedSubBlockEnd.gif}

InBlock.gif
InBlock.gif
returnSqlHelper.ExecuteDataset(connectionString,CommandType.StoredProcedure,"Pagination",
InBlock.gif
newSqlParameter("@tblName",this.tblName),
InBlock.gif
newSqlParameter("@strGetFields",this.strGetFields),
InBlock.gif
newSqlParameter("@fldName",this.fldName),
InBlock.gif
newSqlParameter("@PageSize",this.pagesize),
InBlock.gif
newSqlParameter("@PageIndex",this.pageindex),
InBlock.gif
newSqlParameter("@doCount",this.docount),
InBlock.gif
newSqlParameter("@OrderType",this.ordertype),
InBlock.gif
newSqlParameter("@strWhere",this.strwhere)
InBlock.gif);
ExpandedSubBlockEnd.gif}

InBlock.gif
InBlock.gif
InBlock.gif
publicintGetCount()
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
if(!this.docount)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
thrownewArgumentException("要返回总数统计,DoCount属性一定为true");
ExpandedSubBlockEnd.gif}

InBlock.gif
InBlock.gif
InBlock.gif
InBlock.gif
return(int)SqlHelper.ExecuteScalar(connectionString,CommandType.StoredProcedure,"Pagination",
InBlock.gif
newSqlParameter("@tblName",this.tblName),
InBlock.gif
newSqlParameter("@strGetFields",this.strGetFields),
InBlock.gif
newSqlParameter("@fldName",this.fldName),
InBlock.gif
newSqlParameter("@PageSize",this.pagesize),
InBlock.gif
newSqlParameter("@PageIndex",this.pageindex),
InBlock.gif
newSqlParameter("@doCount",this.docount),
InBlock.gif
newSqlParameter("@OrderType",this.ordertype),
InBlock.gif
newSqlParameter("@strWhere",this.strwhere)
InBlock.gif);
ExpandedSubBlockEnd.gif}

InBlock.gif
InBlock.gif
InBlock.gif
publicstaticintMaxPageIndex(intpageindex)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
if(pageindex<10)
InBlock.gif
return10;
InBlock.gif
stringnumstr=pageindex.ToString();
InBlock.gifnumstr
=numstr.Substring(0,numstr.Length-1);
InBlock.gif
InBlock.gif
InBlock.gif
returnConvert.ToInt32(numstr+"0")+10;
InBlock.gif
ExpandedSubBlockEnd.gif}

InBlock.gif
InBlock.gif
publicstaticintMinPageIndex(intpageindex)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
if(pageindex<10)
InBlock.gif
return1;
InBlock.gif
stringnumstr=pageindex.ToString();
InBlock.gifnumstr
=numstr.Substring(0,numstr.Length-1);
InBlock.gif
returnConvert.ToInt32(numstr+"0");
ExpandedSubBlockEnd.gif}

InBlock.gif
ExpandedSubBlockEnd.gif}

InBlock.gif
ExpandedBlockEnd.gif}
这一切准备好之后,我们就可以对数据进行分页程序开发了。 这篇文章也许写得不是很好,同样代码也有很多可以修改的地方,代码我已经测试过,兼容ie和ff2.0。如果有问题,欢迎回帖,也可以 发信息给我。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值