<style type="text/css">
    .tab{border-collapse:collapse; margin:0 auto;}
    .tab th{ border:#000 solid 1px; line-height:24px;}
    .tab td{border:#000 solid 1px; line-height:18px;}
    .tab td.no{color:#f00;}
    </style>

<table class="tab">
        <asp:Repeater ID="Repeater1" runat="server" OnItemCommand="Repeater1_ItemCommand" >
        <HeaderTemplate>
        <tbody>
            <tr>
                <th>555</th>
                <th>666</th>
                <th>777</th>
            </tr>
         </tbody>
        </HeaderTemplate>
        <ItemTemplate>
            <tr>
                <td><%# DataBinder.Eval(Container.DataItem,"SendCentreID") %>
                </td>
                <td><%# DataBinder.Eval(Container.DataItem,"Mo") %>
                </td>
                <td><%# DataBinder.Eval(Container.DataItem,"Stat") %>
                </td>
                <td>
                    <asp:Button ID="Button3" runat="server" UseSubmitBehavior="true" Text="Button" CommandArgument='<%# DataBinder.Eval(Container.DataItem,"ID") %>' CommandName="ButtonOnClick" />
                </td>
            </tr>
        </ItemTemplate>
        <AlternatingItemTemplate>
            <tr>
                <td class="no"><%# DataBinder.Eval(Container.DataItem,"SendCentreID") %>
                </td>
                <td class="no"><%# DataBinder.Eval(Container.DataItem,"Mo") %>
                </td>
                <td class="no"><%# DataBinder.Eval(Container.DataItem,"Stat") %>
                </td>
                <td>
                    <asp:Button ID="Button3" runat="server" Text="Button" UseSubmitBehavior="true" CommandArgument='<%# DataBinder.Eval(Container.DataItem,"ID") %>' CommandName="ButtonOnClick" />
                </td>
            </tr>
        </AlternatingItemTemplate>
        <FooterTemplate>
            <tr>
                <td colspan="4">
                    <asp:LinkButton ID="FirstPage" runat="server" OnClick="FirstPage_OnClick">首页</asp:LinkButton>
                
                    <asp:LinkButton ID="UpPage" runat="server" OnClick="UpPage_OnClick">上一页</asp:LinkButton>
                    
                    第<asp:Label ID="ThisPage" runat="server" Text="1"></asp:Label>页 共<asp:Label ID="AllCountPage" runat="server" Text="1"></asp:Label>页
                    
                    <asp:LinkButton ID="NextPage" runat="server" OnClick="NextPage_OnClick">下一页</asp:LinkButton>
                
                    <asp:LinkButton ID="LastPage" runat="server" OnClick="LastPage_OnClick">末页</asp:LinkButton>
                    
                    <asp:TextBox ID="CountPage" runat="server"></asp:TextBox>
                    <asp:LinkButton ID="SetCountPage" runat="server" OnClick="SetCountPage_OnClick">转</asp:LinkButton>
                </td>
            </tr>
        </FooterTemplate>
        </asp:Repeater>
        </table>

后台代码

public struct PageState
    {

/// <summary>
        /// 当前页
        /// </summary>
        public int ThisPage;
        /// <summary>
        /// 要显示的页数
        /// </summary>
        public int PageSize;
        /// <summary>
        /// 总页数
        /// </summary>
        public int AllPageCount;
        /// <summary>
        /// 记录数
        /// </summary>
        public int Counts;
    }
    protected PageState pagestate;
    protected String AdoConn = ConfigurationSettings.AppSettings["XueXunTongConn"];
    protected void Page_Load(object sender, EventArgs e)
    {
        pagestate.PageSize = 16;
        pagestate.ThisPage = 1;
        if (!Page.IsPostBack)
        {
            GetData("");
        }
    }
    protected void Page_PreRenderComplete(object sender, EventArgs e)
    {
        
    }

/// <summary>
    /// 设置当然页数
    /// </summary>
    /// <param name="Count"></param>
    private void SetCount()
    {
        if (pagestate.ThisPage > pagestate.AllPageCount)
        {
            pagestate.ThisPage = pagestate.AllPageCount;
        }
        ((Label)Repeater1.Controls[this.Repeater1.Controls.Count - 1].FindControl("ThisPage")).Text = pagestate.ThisPage.ToString();
        TextBox TB = (TextBox)Repeater1.Controls[this.Repeater1.Controls.Count - 1].FindControl("CountPage");
        TB.Text = pagestate.ThisPage.ToString();
        ((Label)Repeater1.Controls[this.Repeater1.Controls.Count - 1].FindControl("AllCountPage")).Text = pagestate.AllPageCount.ToString();
    }

protected void GetData(String Where)
    {
        DataSet DS = SQLHelp.PageView("SendCentreMo", "*", pagestate.PageSize, pagestate.ThisPage, ref pagestate.AllPageCount, ref pagestate.Counts, "id", true, Where, "id", false);
       Repeater1.DataSource = DS;
       Repeater1.DataBind();
       SetCount();
    }
    //转
    protected void SetCountPage_OnClick(object sender, EventArgs e)
    {
        TextBox TB = (TextBox)Repeater1.Controls[this.Repeater1.Controls.Count - 1].FindControl("CountPage");
        if (TB.Text == "")
        {
            return;
        }
        try
        {
            pagestate.ThisPage = Int32.Parse(TB.Text);
            if (pagestate.ThisPage <= 0)
            {
                pagestate.ThisPage = 1;
            }
        }
        catch
        {
            pagestate.ThisPage = 1;
        }
        GetData("");
    }
    //首页
    protected void FirstPage_OnClick(object sender, EventArgs e)
    {
        pagestate.ThisPage = 1;
        GetData("");
    }
    //末页
    protected void LastPage_OnClick(object sender, EventArgs e)
    {
        try
        {
            pagestate.ThisPage = Int32.Parse(((Label)Repeater1.Controls[this.Repeater1.Controls.Count - 1].FindControl("AllCountPage")).Text);
        }
        catch
        {
            pagestate.ThisPage = 1;
        }
        GetData("");
    }
    //上一页
    protected void UpPage_OnClick(object sender, EventArgs e)
    {
        try
        {
            pagestate.ThisPage = Int32.Parse(((Label)Repeater1.Controls[this.Repeater1.Controls.Count - 1].FindControl("ThisPage")).Text);
            pagestate.ThisPage--;
        }
        catch
        {
            pagestate.ThisPage = 1;
        }

if (pagestate.ThisPage <= 0)
        {
            pagestate.ThisPage = 1;
        }
        GetData("");
    }
    //下一页
    protected void NextPage_OnClick(object sender, EventArgs e)
    {
        try
        {
            pagestate.ThisPage = Int32.Parse(((Label)Repeater1.Controls[this.Repeater1.Controls.Count - 1].FindControl("ThisPage")).Text);
            pagestate.ThisPage++;
        }
        catch
        {
            pagestate.ThisPage = 1;
        }
        GetData("");
    }

protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        switch (e.CommandName)
        {
            case "ButtonOnClick":
                int i = Convert.ToInt32(e.CommandArgument);
                break;
        }
    }

asp.net Repeater使用例子,包括分页的更多相关文章

  1. ASP.NET Repeater控件实现简单分页

    早上,有看MSDN,看到了 PagedDataSource 类 http://msdn.microsoft.com/zh-cn/library/system.web.ui.webcontrols.pa ...

  2. Repeater控件的分页实现

    本文讲解Repeater控件与PagedDataSource相结合实现其分页功能.PagedDataSource 类封装那些允许数据源控件(如 DataGrid.GridView)执行分页操作的属性. ...

  3. 前端使用AngularJS的$resource,后端ASP.NET Web API,实现分页、过滤

    在上一篇中实现了增删改查,本篇实现分页和过滤. 本系列包括: 1.前端使用AngularJS的$resource,后端ASP.NET Web API,实现增删改查2.前端使用AngularJS的$re ...

  4. [ASP.NET]asp.net Repeater控件的使用方法

    asp.net Repeater控件的使用方法 -- : 4770人阅读 评论() 收藏 举报 asp.netserveraspdatasetdeletexhtml 今天学习了,Repeater控件 ...

  5. Asp.Net中的三种分页方式

    Asp.Net中的三种分页方式 通常分页有3种方法,分别是asp.net自带的数据显示空间如GridView等自带的分页,第三方分页控件如aspnetpager,存储过程分页等. 第一种:使用Grid ...

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

    ASP.NET repeater添加序号列的方法 1.<itemtemplate> <tr><td> <%# Container.ItemIndex + 1% ...

  7. ASP.NET Repeater 控件分页

    protected void Page_Load(object sender, EventArgs e) { HttpContext context = HttpContext.Current; co ...

  8. ASP.NET Zero--14.一个例子(7)商品分类管理-分类搜索及分页

    分类搜索实现 1.添加搜索框 打开Index视图,添加一个搜索框,代码如下: ... <div class="portlet light"> <div class ...

  9. repeater控件实现分页

    repeater控件实现排序的方法,今天我再向大家介绍repeater控件如何实现分页的效果. 分页分为真分页和假分页. 真分页:控件上一页需要显示多少数据,就从数据库取出并绑定多少数据,每次换页时都 ...

随机推荐

  1. mahout推荐系统

    本章包含以下内容: 首先看一下实战中的推荐系统 推荐引擎的精度评价 评价一个引擎的准确率和召回率 在真实数据集:GroupLens 上评价推荐系统 我们每天都会对喜欢的.不喜欢的.甚至不关心的事情有很 ...

  2. JS之Fetch

    细节叙述见以下链接:https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch 1 基本概念:  WindowOrWo ...

  3. FormShortCut MainForm 和 二级FORM

    发现,主FORM 定义的快捷键,在二级FORM里也有效. 反过来,就无效. 这样的话,就要考虑 快捷键的冲突问题 了,本来以为不同的FORM 是独立的. http://codeverge.com/em ...

  4. POJ 1504 Adding Reversed Numbers

    /*Sample Input 3 24 1 4358 754 305 Sample Output 34 1998 */ 值得总结的几点就是: 1.atoi函数将字符串转化为整型数字(类似于强制转换) ...

  5. Oracle导出空表解决办法

    在oracle 11g 中,发现传统的exp不能导出空的表 oracle 11g 新增了一个参数:deferred_segment_creation,含义是段延迟创建,默认是true.具体是什么意思呢 ...

  6. 用MyEclipse JPA创建项目(一)

    MyEclipse 3.15 Style——在线购买低至75折!火爆开抢>> [MyEclipse最新版下载] 本教程介绍了MyEclipse中的一些基于JPA的功能. 阅读本教程时,了解 ...

  7. MyEclipse持续性开发教程:用JPA和Spring管理数据(一)

    MyEclipse开年钜惠 在线购买低至75折!立即开抢>> [MyEclipse最新版下载] 本教程介绍了MyEclipse中的一些基于JPA / Spring的功能.有关设置JPA项目 ...

  8. IOS编码转化

    原文地址:http://blog.csdn.net/huifeidexin_1/article/details/7883984 iOS中编码转化 1.UTF-8转化 NSString *data =  ...

  9. Java快速排序和归并排序详解

    快速排序 概述 快速排序算法借鉴的是二叉树前序遍历的思想,最终对数组进行排序. 优点: 对于数据量比较大的数组排序,由于采用的具有二叉树二分的思想,故排序速度比较快 局限 只适用于顺序存储结构的数据排 ...

  10. nodejs tutorials

    设置npm的镜像为淘宝镜像 npm config list npm config set registry " https://registry.npm.taobao.org "