Repeater03-Repeater分页

Repeater03-Repeater分页

在这个案例中,实现的是Repeater的分页功能。

前台代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ReapterPaging.aspx.cs" Inherits="ReapterPaging" %>

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

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <style>
        /*=============表格 Begin==============*/
        #tablePrint {
            width: 100%;
            margin-bottom: 5px;
        }

            #tablePrint, #tablePrint th, #tablePrint td {
                border: 1px solid #ccc;
                border-collapse: collapse;
                padding: 2px;
            }

                #tablePrint tr:nth-child(odd) {
                    background-color: rgb(235, 240, 255);
                }
        /*=============表格 End================*/

        /*=============分页 Begin==============*/
        #divPageIndex {
            border: 0;
            padding: 0;
            position: absolute;
            bottom: 10px;
            margin: 0 auto;
        }

            #divPageIndex a {
                border: 0;
                padding: 0;
            }

        #AspNetPager1 {
            float: left;
            padding-left: 5px;
        }

            #AspNetPager1 select {
                margin-top: 5px;
                width: 60px;
                white-space: nowrap;
            }

            #AspNetPager1 a {
                display: block;
                height: 20px;
                line-height: 20px;
                text-decoration: none;
                padding: 0 10px;
                margin-left: 5px;
                _width: 1px;
                white-space: nowrap;
                color: #000;
            }

            #AspNetPager1 span {
                display: block;
                height: 20px;
                line-height: 20px;
                min-width: 32px;
                text-align: center;
                float: left;
                border: 1px solid #ccc;
                margin: 5px;
                margin-left: 0px;
            }

                #AspNetPager1 span:hover {
                    float: left;
                    border: 1px solid #000;
                    cursor: pointer;
                }

        .pTotalRecords {
            height: 22px;
            line-height: 22px;
            padding-left: 5px;
        }

            .pTotalRecords select {
                width: 60px;
                white-space: nowrap;
                margin-top: 5px;
            }

        .spanRed {
            color: red;
            padding: 0 3px;
        }
        /*=============分页 End================*/
    </style>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:Repeater ID="Repeater1" runat="server">
                <HeaderTemplate>
                    <table id="tablePrint" class="tbShow">
                        <tr class="th">
                            <td nowrap width="35px;" align="center">序号</td>
                            <td nowrap>姓名</td>
                            <td nowrap>性别</td>
                            <td nowrap>手机</td>
                            <td nowrap>邮箱</td>
                        </tr>
                </HeaderTemplate>
                <ItemTemplate>
                    <tr id="trIdrep" οnmοuseοver="this.bgColor='#C4DFF7'" οnmοuseοut="this.bgColor='#ffffff'">
                        <td nowrap><%#Container.ItemIndex+1%> </td>
                        <td nowrap><%#Eval("userName")%></td>
                        <td nowrap><%#Eval("userSex")%></td>
                        <td nowrap><%#Eval("userPhone")%></td>
                        <td nowrap><%#Eval("userEmail")%></td>
                    </tr>
                </ItemTemplate>
                <FooterTemplate>
                    </table>
                </FooterTemplate>
            </asp:Repeater>
            <!--分页-->
            <div class="divPageIndex">

                <webdiyer:AspNetPager ID="AspNetPager1" runat="server"
                    ShowPageIndexBox="Always" PageIndexBoxType="DropDownList"
                    TextBeforePageIndexBox="转到" HorizontalAlign="NotSet" EnableTheming="true"
                    FirstPageText="首页" LastPageText="尾页" NextPageText="后页"
                    PrevPageText="前页" AlwaysShow="true" CurrentPageButtonPosition="Beginning"
                    CustomInfoTextAlign="Right" PagingButtonLayoutType="Span" ShowMoreButtons="False"
                    ShowNavigationToolTip="true" SubmitButtonText="Go"
                    TextAfterPageIndexBox="页" LayoutType="table" OnPageChanging="AspNetPager1_PageChanging">
                </webdiyer:AspNetPager>

                <p class="pTotalRecords">
                    | 
              每页<asp:DropDownList
                  ID="ddlPrePageNumber" runat="server" AutoPostBack="True"
                  OnSelectedIndexChanged="ddlPrePageNumber_SelectedIndexChanged">
                  <asp:ListItem>10</asp:ListItem>
                  <asp:ListItem>50</asp:ListItem>
                  <asp:ListItem>100</asp:ListItem>
                  <asp:ListItem>500</asp:ListItem>
                  <asp:ListItem>1000</asp:ListItem>
                  <asp:ListItem>5000</asp:ListItem>
              </asp:DropDownList>记录 | 
            共<span class="spanRed"><%=this.AspNetPager1.PageCount%></span>页

            | <b>共<span class="spanRed"><%=this.AspNetPager1.RecordCount%></span>条记录</b>
                </p>
            </div>
        </div>
    </form>
</body>
</html>

后台代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class ReapterPaging : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            DataBindRepeater();
        }
    }

    private void DataBindRepeater()
    {
        using (SqlConnection con = new SqlConnection(SqlHelper._ConnectionString))
        {
            this.AspNetPager1.PageSize = this.ddlPrePageNumber.SelectedItem.Value.ToInt32();    //设置每页显示的记录条数
            string strSqlCount = "select count(*) from UserInfo";
            this.AspNetPager1.RecordCount = Convert.ToInt32(SqlHelper.ExecuteScalar(CommandType.Text, strSqlCount));//数据条数
            string strSql = "select * from UserInfo";
            SqlDataAdapter dr = new SqlDataAdapter(strSql, con);
            DataSet ds = new DataSet();
            //填充数据[ Ds,开始,最大数,表名]
            dr.Fill(ds, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, "UserInfo");
            this.Repeater1.DataSource = ds.Tables[0];
            this.Repeater1.DataBind();
        }
    }

    //点击分页时
    protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
    {
        AspNetPager1.CurrentPageIndex = e.NewPageIndex;
        DataBindRepeater();
    }

    //每页显示数据数
    protected void ddlPrePageNumber_SelectedIndexChanged(object sender, EventArgs e)
    {
        AspNetPager1.CurrentPageIndex = 1;
        //DataBindRepeater();
    }
}

页面展示:


注意要点:

引用


分页


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值