zoukankan      html  css  js  c++  java
  • AspNetPager分页控件整理

    AspNetPager1.PageSize=10;     //设置每也显示的记录条数
    AspNetPager1.RecordCount //总记录数


    <webdiyer:AspNetPager ID="AspNetPager1" runat="server"
    AlwaysShow="True" //总是显示分页控件,即使要分页的数据只有一页
    OnPageChanged="AspNetPager1_PageChanged" //分页发生改变时触发事件
    UrlPaging="true" //通过URL传递分页信息的方式来分页。如果设为true,禁用ViewState也能达到效果。如果设置为false,禁用了viewstate则无法实现分页.
    NumericButtonTextFormatString="[{0}]" //页索引数字显示的格式
    ShowCustomInfoSection="Left">   //显示当前页和总页数信息,默认值不显示,为left则将显示在页索引前,为right则为页索引后            </webdiyer:AspNetPager>
    ----------------------------------
    protected void AspNetPager1_PageChanging(object src, PageChangingEventArgs e)
    {
    if (CheckBox1.Checked)
    e.Cancel = true;//禁用分页
    label1.Text = "PageChanging 事件被引发,NewPageIndex 的值是:" + e.NewPageIndex;//当前页索引
    }

        protected void AspNetPager1_PageChanged(object src, EventArgs e)
    {
    label2.Text = "PageChanged事件被引发,当前页索引是:" + AspNetPager1.CurrentPageIndex;//当前页
    }
    -------------------------------
    ShowDisAbledButtons:true/false 设置当前页为1页时时候显示首页和上一页
    ShowFirstLast: true/False 是否显示首页和尾页
    ShowPrevNext: true/false 是否显示 上一页 和 下一页
    ShowPageIndex:true/false 是否显示中间的页号

    --------DataList 通过开始的记录数和当前页的结尾记录数 存储过程查询------------------------------
    protected void Page_Load(object sender, EventArgs e)
    {
    if (!IsPostBack)
    {
    //存储过程查询 orders表中的记录数
    int totalOrders = (int)SqlHelper.ExecuteScalar(CommandType.StoredProcedure, "P_GetOrderNumber");
    AspNetPager1.RecordCount = totalOrders;//获取总页数
    bindData();
    }
    }

        void bindData()
    {
    //获取 存储在 WebConfig中的 存储过程的名称 P_GetPagedOrders2000
    DataList1.DataSource = SqlHelper.ExecuteReader(CommandType.StoredProcedure, ConfigurationManager.AppSettings["pagedSPName"],
    new SqlParameter("@startIndex", AspNetPager1.StartRecordIndex),//开始的记录数
    new SqlParameter("@endIndex", AspNetPager1.EndRecordIndex));//结束的记录数
    Response.Write(AspNetPager1.StartRecordIndex);
    Response.Write("<br/>"+AspNetPager1.EndRecordIndex);
    DataList1.DataBind();
    }
    protected void AspNetPager1_PageChanged(object src, EventArgs e)
    {
    bindData();
    }
    存储过程:查询 Orders表中的数据
    CREATE procedure [dbo].[P_GetPagedOrders2000]
    (@startIndex int, --开始号数
    @endIndex int     ----结束号数
    )
    as
    set nocount on
    declare @indextable table(id int identity(1,1),nid int)
    set rowcount @endIndex
    insert into @indextable(nid) select orderid from orders order by orderid desc--从order表中查询orderid插入到@indextable表中的nid列
    select O.orderid,O.orderdate,O.customerid,C.CompanyName,E.FirstName+' '+E.LastName as EmployeeName
    from orders O
    left outer join Customers C
    on O.CustomerID=C.CustomerID
    left outer join Employees E
    on O.EmployeeID=E.EmployeeID
    inner join @indextable t on
    O.orderid=t.nid
    where t.id between @startIndex and @endIndex order by t.id
    set nocount off
    RETURN
    ----------------------------
    SET ROWCOUNT:使 SQL Server 在返回指定的行数之后停止处理查询。
    set nocount on :阻止在结果中返回可显示受 Transact-SQL 语句影响的行数的消息。
    当 SET NOCOUNT 为 ON 时,不返回计数(表示受 Transact-SQL 语句影响的行数)。当 SET NOCOUNT 为 OFF 时,返回计数。

    即使当 SET NOCOUNT 为 ON 时,也更新 @@ROWCOUNT 函数。

    当 SET NOCOUNT 为 ON 时,将不向客户端发送存储过程中每个语句的 DONE_IN_PROC 消息。使用由 SQL Server 2005 提供的实用工具执行查询时,其结果会防止在 Transact-SQL 语句(例如 SELECT、INSERT、UPDATE 和 DELETE)的末尾显示 nn rows affected。

    如果存储过程中包含的一些语句并不返回许多实际数据,则该设置由于大量减少了网络流量,因此可显著提高性能。

    SET NOCOUNT 设置是在执行或运行时设置,而不是在分析时设置。

    @@ROWCOUNT:返回受上一语句影响的行数。
    -------Reapeter分页----------------------------
    protected void Page_Load(object sender, EventArgs e)
    {
    if (!IsPostBack)
    {
    int totalOrders = (int)SqlHelper.ExecuteScalar(CommandType.StoredProcedure, "P_GetOrderNumber");
    AspNetPager1.RecordCount = totalOrders;
    //bindData(); //使用url分页,只需在分页事件处理程序中绑定数据即可,无需在Page_Load中绑定,否则会导致数据被绑定两次
    }
    }

        void bindData()
    {
    Repeater1.DataSource = SqlHelper.ExecuteReader(CommandType.StoredProcedure, ConfigurationManager.AppSettings["pagedSPName"],
    new SqlParameter("@startIndex", AspNetPager1.StartRecordIndex),
    new SqlParameter("@endIndex", AspNetPager1.EndRecordIndex));
    Repeater1.DataBind();
    }

        protected void AspNetPager1_PageChanged(object src, EventArgs e)
    {
    bindData();
    }

    Dmeo:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Configuration;
    using Microsoft.ApplicationBlocks.Data;
    using System.Data;
    using System.Data.SqlClient;
    using GotDotNet.ApplicationBlocks.Data;
    
    namespace WebAppPageTest
    {
        public partial class _Default : System.Web.UI.Page
        {
            public static readonly  string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    int totalOrders = (int)SqlHelper.ExecuteScalar(connStr, CommandType.StoredProcedure, ConfigurationManager.AppSettings["P_GetOrderNumber"].ToString(),
                        new SqlParameter("@pagesize ", AspNetPager1.PageSize),
                        new SqlParameter("@pageindex ", AspNetPager1.StartRecordIndex),
                        new SqlParameter("@docount",1));
                    AspNetPager1.RecordCount = totalOrders;
                    //bindData(); //使用url分页,只需在分页事件处理程序中绑定数据即可,无需在Page_Load中绑定,否则会导致数据被绑定两次
                }
            }
            void bindData()
            {
                Repeater1.DataSource = SqlHelper.ExecuteDataset(connStr,CommandType.StoredProcedure, ConfigurationManager.AppSettings["pagedSPName"].ToString(),
                    new SqlParameter("@startIndex", AspNetPager1.StartRecordIndex),
                    new SqlParameter("@endIndex", AspNetPager1.EndRecordIndex));
                Repeater1.DataBind();
            }
            protected void AspNetPager1_PageChanged(object sender, EventArgs e)
            {
                bindData();
            }
        }
    }
    
    

    html:

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebAppPageTest._Default" %>
    
    <%@ 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>AspNetPager示例—Repeater分页示例</title>
        <style type="text/css">
    /*网易风格*/
    .anpager .cpb {background:#1F3A87 none repeat scroll 0 0;border:1px solid #CCCCCC;color:#FFFFFF;font-weight:bold;margin:5px 4px 0 0;padding:4px 5px 0;}
    .anpager a {background:#FFFFFF none repeat scroll 0 0;border:1px solid #CCCCCC;color:#1F3A87;margin:5px 4px 0 0;padding:4px 5px 0;text-decoration:none}
    .anpager a:hover{background:#1F3A87 none repeat scroll 0 0;border:1px solid #1F3A87;color:#FFFFFF;}
    
    /*拍拍网风格*/
    .paginator { font: 11px Arial, Helvetica, sans-serif;padding:10px 20px 10px 0; margin: 0px;}
    .paginator a {padding: 1px 6px; border: solid 1px #ddd; background: #fff; text-decoration: none;margin-right:2px}
    .paginator a:visited {padding: 1px 6px; border: solid 1px #ddd; background: #fff; text-decoration: none;}
    .paginator .cpb {padding: 1px 6px;font-weight: bold; font-size: 13px;border:none}
    .paginator a:hover {color: #fff; background: #ffa501;border-color:#ffa501;text-decoration: none;}
    
    /*迅雷风格*/
    .pages { color: #999 }
    .pages a, .pages .cpb { text-decoration:none;float: left; padding: 0 5px; border: 1px solid #ddd;background: #ffff;margin:0 2px; font-size:11px; color:#000;}
    .pages a:hover { background-color: #E61636; color:#fff;border:1px solid #E61636; text-decoration:none;}
    .pages .cpb { font-weight: bold; color: #fff; background: #E61636; border:1px solid #E61636;}
    
    .code{font-weight:bold;color:blue}
    </style>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            该示例演示如何使用AspNetPager分页控件对Repeater控件进行分页
        </div>
        <br />
        <webdiyer:AspNetPager id="AspNetPager1" runat="server" width="100%" urlpaging="true" showpageindexbox="Always"
            pageindexboxtype="DropDownList" textbeforepageindexbox="Go To Page: " horizontalalign="right"
            pagesize="5" onpagechanged="AspNetPager1_PageChanged" enabletheming="true" CssClass="anpager" CurrentPageButtonClass="cpb" FirstPageText="首页" LastPageText="尾页" NextPageText="后页" PrevPageText="前页">
            </webdiyer:AspNetPager>
        <asp:Repeater ID="Repeater1" runat="server">
            <HeaderTemplate>
                <table width="100%" border="1" cellspacing="0" cellpadding="4" style="border-collapse: collapse">
                    <tr style="background-color: #CCCCFF">
                        <th style=" 15%">
                            专业编号
                        </th>
                        <th style=" 15%">
                            专业名称
                        </th>
                        <th style=" 30%">
                            备注信息
                        </th>
                    </tr>
            </HeaderTemplate>
            <ItemTemplate>
                <tr style="background-color: #FAF3DC">
                    <td>
                        <%#DataBinder.Eval(Container.DataItem, "MajorID")%>
                    </td>
                    <td>
                        <%#DataBinder.Eval(Container.DataItem, "Name")%>
                    </td>
                    <td>
                        <%#DataBinder.Eval(Container.DataItem, "Remark")%>
                    </td>
                </tr>
            </ItemTemplate>
            <AlternatingItemTemplate>
                <tr style="background-color: #eaeaea">
                    <td>
                        <%#DataBinder.Eval(Container.DataItem, "MajorID")%>
                    </td>
                    <td>
                        <%#DataBinder.Eval(Container.DataItem, "Name")%>
                    </td>
                    <td>
                        <%#DataBinder.Eval(Container.DataItem, "Remark")%>
                    </td>
                </tr>
            </AlternatingItemTemplate>
            <FooterTemplate>
                </table>
            </FooterTemplate>
        </asp:Repeater>
        <webdiyer:AspNetPager ID="AspNetPager2" runat="server" CloneFrom="AspNetPager1" CssClass="paginator" CurrentPageButtonClass="cpb" FirstPageText="首页" LastPageText="尾页" NextPageText="下一页" PrevPageText="上一页">
        </webdiyer:AspNetPager>
        </form>
    </body>
    </html>
    
    

    demodownload

  • 相关阅读:
    2016多校赛1 A 期望 B SG博弈,状压 D 倍增,二分
    POWOJ 1739: 魔术球问题 DAG最小路径覆盖转最大流
    Codeforces 743D 树形dp
    线性规划与网络流24题 索引
    WangEditor富文本编辑器的简单使用,并将文本数据发往后台
    SSRF
    关于Blind XXE
    blind xxe攻击
    linux awk命令详解
    kali
  • 原文地址:https://www.cnblogs.com/Leo_wl/p/1762966.html
Copyright © 2011-2022 走看看