为Repeater添加分页

以下是程序中的一个页面,PagedDataSource封装了DataGrid,GridView的与分页相关的属性,本方法同样适用于DataList等...

 

CallingList.aspx

 

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

<!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>
    <link rel="stylesheet" href="style.css" />
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table align="center" cellpadding="2" cellspacing="1" class="tb" style="table-layout: fixed">
            <tr align="center" class="tc">
                <td>访问方式</td>
                <td>访问时间</td>
                <td>客户名称</td>
                <td>客户电话</td>
                <td>接待人</td>
                <td>备注</td>
            </tr>
            <asp:Repeater ID="showCalling" runat="server">
                <ItemTemplate>
                    <tr align="center" bgcolor="#ffffff" οnmοuseοver="this.style.background='#f0f0f0';" οnmοuseοut="this.style.background='#ffffff';">
                        <td><%# DataBinder.Eval(Container.DataItem,"c_calltype") %></td>
                        <td><%# DataBinder.Eval(Container.DataItem,"c_calldate") %></td>
                        <td><%# DataBinder.Eval(Container.DataItem,"c_client") %></td>
                        <td><%# DataBinder.Eval(Container.DataItem,"c_tell") %></td>
                        <td><%# DataBinder.Eval(Container.DataItem,"c_worker") %></td>
                        <td style="left: 0px; width: 100%; word-wrap: break-word; 130; 0pt"><%# DataBinder.Eval(Container.DataItem,"c_memo") %></td>
                    </tr>
                </ItemTemplate>
            </asp:Repeater>
            <tr align="right" class="tc">
                <td colspan="6">
                    <asp:Label ID="curpage" runat="server"></asp:Label>&nbsp;&nbsp;
                    <asp:HyperLink ID="pre" runat="Server" Text="上一页"></asp:HyperLink>&nbsp;
                    <asp:HyperLink ID="next" runat="server" Text="下一页"></asp:HyperLink>
                </td>
            </tr>
        </table>
        <br />
        <center><a href="AddCalling.aspx" target="right">添加客户访问记录</a></center>
    </div>
    </form>
</body>
</html>


 

  CallingList.aspx.cs

 

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

public partial class CallingList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        PagedDataSource pds = new PagedDataSource();
        pds.DataSource = new clsSqlRun().getCalling().Tables[0].DefaultView;
        pds.AllowPaging = true;
        pds.PageSize = 10;

        int currentPage;
        if (Request.QueryString["page"] != null)
        {
            try
            {
                currentPage = Int32.Parse(Request.QueryString["page"].ToString());
            }
            catch (Exception ex)
            {
                currentPage = 1;
            }
        }
        else {
            currentPage = 1;
        }
        
        pds.CurrentPageIndex = currentPage-1;
        curpage.Text = "当前页:" + currentPage + " 页  共 " + pds.PageCount + " 页 ";

        if (!pds.IsFirstPage)
        {
            pre.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(currentPage-1);
        }

        if (!pds.IsLastPage)
        {
            next.NavigateUrl = Request.CurrentExecutionFilePath + "?page=" + Convert.ToString(currentPage+1);
        }

        showCalling.DataSource = pds;
        showCalling.DataBind();
    }
}


 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值