热门:网页模板.net视频教程JQueryMVCjsonExtJs源码示例三级联动JQuery菜单
您现在的位置:.Net中文社区>> .Net编程>>正文内容

利用AspNetPager控件分页实例

发布时间:2008年11月30日点击数:

AspNetPager控件官方下载地址:http://www.webdiyer.com/download/default.aspx

1、AspNetPager 控件简单分页实例
.aspx文件

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="paging.aspx.cs" Inherits="VoteInfo.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>
    <form id="form1" runat="server">
     <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="width:15%">姓名</th>
        <th style="width:15%">性别</th>
        <th style="width:30%">年龄</th>
        <th style="width:20%">毕业院校专业</th>
        <th style="width:20%">学位学历</th></tr>
        </HeaderTemplate>
        <ItemTemplate>
        <tr style="background-color:#FAF3DC">
        <td><%#DataBinder.Eval(Container.DataItem,"Name")%></td>
        <td><%#DataBinder.Eval(Container.DataItem, "Sex")%></td>
        <td><%#DataBinder.Eval(Container.DataItem, "Age")%></td>
        <td><%#DataBinder.Eval(Container.DataItem, "GraduateUnversity")%></td>
        <td><%#DataBinder.Eval(Container.DataItem, "Degree")%></td>
        </tr>
        </ItemTemplate>
        <FooterTemplate>
        </table>
        </FooterTemplate>
        </asp:Repeater>
     <webdiyer:AspNetPager ID="AspNetPager1" runat="server"  
         onpagechanged="AspNetPager1_PageChanged"  
         CurrentPageButtonPosition="Center"  
         CustomInfoHTML="第%CurrentPageIndex%页,共%PageCount%页,每页%PageSize%条"  
         FirstPageText="首页" LastPageText="尾页" LayoutType="Table" NextPageText="下一页"  
         PageIndexBoxType="DropDownList" PagingButtonLayoutType="Span"  
         PrevPageText="上一页" ShowCustomInfoSection="Left" SubmitButtonText="Go"  
         TextAfterPageIndexBox="页" TextBeforePageIndexBox="转到">
     </webdiyer:AspNetPager>
    </form>
</body>
</html>

.cs代码如下:

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;


namespace VoteInfo
{
    public partial class paging : System.Web.UI.Page
    {
        private DataAccess da = new DataAccess();
        protected void Page_Load(object sender, EventArgs e)
        {
            string sql = "select * from CadreInfo";            
            DataTable dt = new DataTable();
            dt = da.ExecuteDataTable(sql);
            AspNetPager1.RecordCount = dt.Rows.Count;
            this.RPDataBind();
        }


        private void RPDataBind()
        {
            try
            {
                SqlDataAdapter sda=new SqlDataAdapter("select * from CadreInfo",da.ConnectString);
                DataSet ds=new DataSet ();
                AspNetPager1.AlwaysShow =true;
                AspNetPager1.PageSize =20;
                sda.Fill(ds,AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, "dbTable");
                this.Repeater1.DataSource =ds.Tables[0];
                this.Repeater1.DataBind();
            }

            catch { }
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {            
            RPDataBind();
        }

    }

}

  2、AspNetPager 控件调用存储过程分页实例
aspx代码如下:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SP_Paging.aspx.cs" Inherits="FLX.ComplexQuery.SP_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>
    <form id="form1" runat="server">
    <div>
    
    </div>
    <asp:GridView ID="GridView1" runat="server">
    </asp:GridView>
    <webdiyer:AspNetPager ID="AspNetPager1" runat="server"  
        CustomInfoHTML="第%CurrentPageIndex%页,共%PageCount%页,每页%PageSize%条"  
        FirstPageText="首页" LastPageText="尾页" LayoutType="Table" NextPageText="下一页"  
        onpagechanged="AspNetPager1_PageChanged" PageIndexBoxType="DropDownList"  
        PagingButtonLayoutType="Span" PrevPageText="上一页" ShowCustomInfoSection="Left"  
        ShowPageIndexBox="Always" SubmitButtonText="Go" TextAfterPageIndexBox="页"  
        TextBeforePageIndexBox="转到">
    </webdiyer:AspNetPager>
    </form>
</body>
</html>

.cs后台代码:

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using FLX.ORM;


namespace FLX.ComplexQuery
{
    public partial class SP_Paging : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                this.AspNetPager1.RecordCount = (int)FLX.ORM.BrokerFactory.GetBroker(Config.DataBasePath).DataAccess.ExecuteProcScalar("P_GetCounts");
                this.GWBind();
            }

        }


        private void GWBind()
        {
            ArrayList param = new ArrayList();
            param.Add(new ParamInfo("@startIndex", AspNetPager1.StartRecordIndex));
            param.Add(new ParamInfo("@endIndex", AspNetPager1.EndRecordIndex));
            GridView1.DataSource = FLX.ORM.BrokerFactory.GetBroker(Config.DataBasePath).DataAccess.ExecuteProcDataTable("SP_Paging", param);
            GridView1.DataBind();  
        }


        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            this.GWBind();
        }

    }

}

存储过程P_GetCounts代码如下:

create PROCEDURE [dbo].[P_GetCounts]
AS
    select count(GUID) from ConfigDate;
    RETURN

存储过程SP_Paging代码如下:

create  procedure [dbo].[SP_Paging]  
(@startIndex int,
@endIndex int)
as

begin
with temptbl as (
SELECT ROW_NUMBER() OVER (ORDER BY GUID desc)AS Row, * from ConfigDate )
SELECT * FROM temptbl where Row between @startIndex and @endIndex
end

 效果图展示:

          
     AspNetPager控件属性设置,如外观、文本等属性,具体如下图所示:

         

更多模板/案例展示

亚太盛典国际婚纱摄影 本案例由亚太盛典国际婚纱公司所部署,精美的界面,合理的布局是网站的一大特色!
亚太盛典国际婚纱摄影 本案例由亚太盛典国际婚纱公司所部署,精美的界面,合理的布局是网站的一大特色!
关于我们 | 联系我们 | 团队日志 | 网站地图 | 网站合作