`

为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" onmouseover="this.style.background='#f0f0f0';" onmouseout="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();
    }
}


 

 

分享到:
评论

相关推荐

    ASP.NET程序中用Repeater实现分页

    一、程序功能: 为Repeater实现分页 二、窗体设计: 1、新建ASP.NET Web应用程序,命名为Repeater2,保存路径为http://192.168.0.1/Repeater2(注:我机子上的网站的IP是192.168.0.1的主目录是D:\web文件夹)然后...

    使用Repeater分页

    Repeater 控件不具备内置的呈现功能,这表示用户必须通过创建模板为 Repeater 控件提供布局。当该页运行时,Repeater 控件依次通过数据源中的记录为每个记录呈现一个项。 他很简单,用起来也不够强大,但是应了那句...

    ASP.NET repeater添加序号列的方法

    在项目开发过程中,会经常遇到ASP.NET repeater控件添加序号列,有些新手可能还不会,网上搜集整理了一些,需要的朋友可以参考下

    C#自定义分页控件

    二、AspNetPager支持各种数据绑定控件GridView、DataGrid、DataList、Repeater以及自定义的数据绑定控件的分页功能十分强大。 三、AspNetPager分页控件本身并不显示任何数据,而只显示分页导航元素,数据在页面上的...

    asp.net2.0

    为删除数据添加客户端确认 基于用户对修改数据进行限制 分页和排序 分页和排序报表数据 大数据量时提高分页的效率 排序自定义分页数据 创建自定义排序用户界面 自定义按钮行为 GridView里的Button 使用...

    asp.net2.0数据教程

    为删除数据添加客户端确认 基于用户对修改数据进行限制 分页和排序 分页和排序报表数据 大数据量时提高分页的效率 排序自定义分页数据 创建自定义排序用户界面 自定义按钮行为 GridView里的Button 使用...

    ASP.NET2.0数据教程

    为删除数据添加客户端确认 基于用户对修改数据进行限制 分页和排序 分页和排序报表数据 大数据量时提高分页的效率 排序自定义分页数据 创建自定义排序用户界面 自定义按钮行为 GridView里的Button 使用...

    asp.net repeater实现批量删除第1/2页

    批量删除涉及到的内容: 1、删除的SQL语句的拼凑,例如delete... 您可能感兴趣的文章:ASP.NET repeater添加序号列的方法asp.net Repeater取得CheckBox选中的某行某个值的c#写法asp.net repeater手写分页实例代码asp.net

    ASP.NET中Repeater控件高级应用研究

    经过对ASP.NET中Repeater数据控件基本特征的分析,以及对实际应用系统中数据列表功能的提炼...并通过典型应用示例,展示其数据绑定和内嵌web服务器控件,以及数据实现排序分页显示,数据添加、更新和批量删除等功能

    在ASP.NET 2.0中操作数据之四十二:DataList和Repeater数据排序(一)

     DataList和Repeater数据分页里我们学习了如何在DataList里添加分页功能。我们在ProductsBLL类里创建了一个名为GetProductsAsPagedDataSource的方法,它返回一个PagedDataSource对象。当绑定到DataList或Repeater时...

    asp.net中让Repeater和GridView支持DataPager分页

    具体使用的时候,要建一个类库项目,把代码编译成dll后,就可以添加到VS的工具箱里了! 一、自定义Repeater 代码如下: using System.Web.UI; using System.Web.UI.WebControls; namespace WYJ.Web.Controls { /// ...

    我的博客管理系统

    DataList Repeater 的分页功能(1)代码编写 (2)PageDateSource()类 5.购物车: 添加新表,修改TemporyCart表 在BookDiscService中编写两个方法 GetBookDiscByBookId() GetBookDiscById() 在...

    Asp.Net其他页面如何调用Web用户控件写的分页

    在要添加分页的页面加载时添加以下代码:(以图书分类为例) 代码如下: Paging p = Paging1; //Web用户控件的ID p.DataControl = gvBookType; //要绑定数据的控件(此处是GridView) p.TableName = “BookShop_...

    asp.net常用Web服务器控件

    4.1 使用控件显示文本 ...实例 显示长日期格式时间 实例 显示金额格式文本 4.2 使用控件显示图片 实例 显示验证码图片 实例 动态显示用户头像 ...实例 Repeater控件分页 实例 编辑Repeater控件标识商品信息

    如何实现ListView高效分页代码

    ListView选择自动分页时 其实就是添加了一个DataPager分页控件两者间存在着嵌套关系《Repeater与ListView》中提到这样的分页并不是高效的 因为数据源还是返回了所有的数据 而非当前页数据  优化方案及步骤: 1.改...

    C# ASP.NET 模块 - 网上问卷调查模块

    ☆ 功能如下:☆ 问卷题型分为单选、多选和问答; 问卷调查主题管理; 问卷主题选项管理; 添加/编辑问卷主题; TreeView控件绑定XML实现导航; Repeater控件分页;

    asp.net2.0访问ACCESS实例(添加、删除、修改)

    asp.net2.0+access+repeater 我也是个新手,一直在自学asp.net2.0,特别是访问数据库方面。边练习边做了这个实例,算是个留言板吧,希望能跟我一样刚上路的新手朋友有所帮助!...用到了repeater控件的嵌套和分页。

    解析asp.net的分页控件

     AspNetPager.dll这个分页控件主要用于asp.net webform网站,现将整理代码如下 二、代码 1、首先在测试页面Default.aspx页面添加引用 &lt;&#37;@ Register Assembly=AspNetPager Namespace=Wuqi.Webdiyer TagPrefix...

    MyBookShop网上购物管理系统

    图书模糊查询 添加图书 图书排序 分页 4.DateList Repeater GridView DetailView ViewState 的应用 5.购物车: 添加新表,修改TemporyCart表 在BookDiscService中编写两个方法 GetBookDiscByBookId() ...

Global site tag (gtag.js) - Google Analytics