AspNetPager 使用Demo

来源:互联网 发布:linux系统上网 编辑:程序博客网 时间:2024/05/20 00:49

1、Demo网址
              http://blog.csdn.net/emoheshang/article/details/4212909
              http://www.cnblogs.com/zhangyi85/archive/2008/04/12/1150669.html
 
 
 Repeater使用 AspNetPager分页控件
 
 前台页面:
 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Paging.aspx.cs" Inherits="Paging" %>

 <%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 <html xmlns="http://www.w3.org/1999/xhtml" >
 <head runat="server">
  <title>无标题页</title>
 </head>
 <body style="text-align: center">
  <form id="form1" runat="server">
  <div style="text-align: center">
   <asp:GridView ID="GridView1" runat="server" PageSize="3" Width="379px" AutoGenerateColumns="False">
    <Columns>
     <asp:BoundField DataField="proID" />
     <asp:BoundField DataField="proName" />
     <asp:BoundField DataField="proNum" />
     <asp:BoundField DataField="proPrice" />
     <asp:BoundField DataField="totalPrice" />
    </Columns>
   </asp:GridView>
  
  </div>
   &nbsp;
   &nbsp;&nbsp;<br />
   <br />
   <webdiyer:AspNetPager ID="pageBind" runat="server" AlwaysShow="True" FirstPageText="<<"
    HorizontalAlign="Right" LastPageText=">>" NextPageText=">" NumericButtonCount="5"
    NumericButtonTextFormatString="-{0}-" OnPageChanged="pageBind_PageChanged" PageSize="5"
    PrevPageText="<" ShowBoxThreshold="2" ShowCustomInfoSection="Left" ShowInputBox="Always"
    Width="382px">
   </webdiyer:AspNetPager>
  </form>
 </body>
 </html>
 
 
 
2、事例 网址:
                http://www.cnblogs.com/LittleFeiHu/archive/2011/02/23/1962297.html
 
 
 后台:
  protected void Page_Load(object sender, EventArgs e)
    {
        Bind();
    }
    private void Bind()
    {
        int pageindex = 1;
        int pagenum = AspNetPager1.PageSize;
        if (Request["page"] != null)
        {
            pageindex =Convert.ToInt32(Request["page"]);
        }
        DataSet ds = new DataSet();
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ToString ());
        SqlConnection con1 = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ToString());
        SqlDataAdapter sda = new SqlDataAdapter("select top (@pagenum) * from pagetest where id not in (select top  (@pagenum*(@pageindex-1)) id from pagetest)", con);
        sda.SelectCommand.Parameters.AddWithValue("pagenum",pagenum);
        sda.SelectCommand.Parameters.AddWithValue("pageindex",pageindex);
        sda.Fill(ds);
        SqlCommand cmd = new SqlCommand("select count(*) from pagetest", con1);
        con1.Open();
        AspNetPager1.RecordCount =Convert.ToInt32(cmd.ExecuteScalar());
        con.Close();
        AspNetPager1.CustomInfoHTML = "共" + AspNetPager1.RecordCount + "条记录      " + AspNetPager1.CurrentPageIndex + "/" + AspNetPager1.PageCount;
        GridView1.DataSource = ds.Tables[0].DefaultView;
        GridView1.DataBind();
    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        Bind();
    }

 
 
 深入分析CurrentPageIndex、RecordCount、 PageCount、 PageSize:

pagecount:

public int PageCount
{
    get
    {
        if (this.RecordCount == 0)
        {
            return 1;
        }
        return (int) Math.Ceiling((double) (((double) this.RecordCount) / ((double) this.PageSize)));
    }
}

recordcount:

public int RecordCount
{
    get
    {
        if (this.cloneFrom != null)
        {
            return this.cloneFrom.RecordCount;
        }
        object obj2 = this.ViewState["Recordcount"];
        if (obj2 != null)
        {
            return (int) obj2;
        }
        return 0;
    }
    set
    {
        this.ViewState["Recordcount"] = value;
    }
}

CurrentPageIndex:

public int CurrentPageIndex
{
    get
    {
        if (this.cloneFrom != null)
        {
            return this.cloneFrom.CurrentPageIndex;
        }
        object obj2 = this.ViewState["CurrentPageIndex"];
        int num = (obj2 == null) ? 1 : ((int) obj2);
        if ((num > this.PageCount) && (this.PageCount > 0))
        {
            return this.PageCount;
        }
        if (num < 1)
        {
            return 1;
        }
        return num;
    }
    set
    {
        int pageCount = value;
        if (pageCount < 1)
        {
            pageCount = 1;
        }
        else if (pageCount > this.PageCount)
        {
            pageCount = this.PageCount;
        }
        this.ViewState["CurrentPageIndex"] = pageCount;
    }
}

PageSize:

public int PageSize
{
    get
    {
        int num;
        if ((!string.IsNullOrEmpty(this.UrlPageSizeName) && !base.DesignMode) && (int.TryParse(this.Page.Request.QueryString[this.UrlPageSizeName], out num) && (num > 0)))
        {
            return num;
        }
        if (this.cloneFrom != null)
        {
            return this.cloneFrom.PageSize;
        }
        object obj2 = this.ViewState["PageSize"];
        if (obj2 != null)
        {
            return (int) obj2;
        }
        return 10;
    }
    set
    {
        this.ViewState["PageSize"] = value;
    }
}


AspNetPager不同版本中的变化:
 http://www.cnblogs.com/mywebworld/archive/2009/10/20/1572778.html

原创粉丝点击