<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. 使用axios发送post请求,将JSON数据改为为form类型

    我的github(PS:希望star):https://github.com/thWinterSun/v-admin 通常前端通过POST请求向服务器端提交数据格式有4中,分别是"appli ...

  2. 【vue系列】elementUI 穿梭框右侧获取当前选中项的值的思路

    最近 做了一个需求 在查询结果的表格中,选取(可多选)一些值,获取到保单号后,打开一个elementUI的穿梭框,然后获取到所有业务员,选取一些业务员后,将上一步获取到的保单号传递给业务员. 画个示意 ...

  3. sql截取字符串后面四位

    方法1: select substr('123456789',length('123456789')-6+1,6) from dual; 方法2: SELECT name, RIGHT(certid, ...

  4. win764位下mysql-5.6.24-x64从安装到登录成功

    1.安装 本人电脑win7,64位,需要安装mysql服务器.版本:mysql-5.6.24-x64.这里我用的是绿色版,免安装.由于免安装的原因,在服务里面并没有mysql的服务.这里我需要打开my ...

  5. oracle多表查询之内连接,外连接语句总结

    后期会补充建表语句. 现有两张表,westemp员工表,有(wtdempid,wtdempname,wtddeptid)列,westdept部门表,有(wtddeptid,wtddeptname,wt ...

  6. MyEclipse WebSphere开发教程:WebSphere 7安装指南(四)

    [周年庆]MyEclipse个人授权 折扣低至冰点!立即开抢>> [MyEclipse最新版下载] 六.管理配置文件 现在您已经安装了WebSphere 7的所有更新,您必须创建一个配置文 ...

  7. MyEclipse WebSphere开发教程:安装和更新WebSphere 6.1, JAX-WS, EJB 3.0(七)

    [周年庆]MyEclipse个人授权 折扣低至冰点!立即开抢>> [MyEclipse最新版下载] MyEclipse支持Java EE技术(如JAX-WS和EJB 3.0),它们以功能包 ...

  8. first head in html 笔记

    目录: 1.了解HTML 2.学会简单构建网页 3.学会将单个的网页放在web上,组成网站 5.学会使用图片 6.严格HTML规范 7.HTML->XHTML 8.学会一点CSS样式 9.了解盒 ...

  9. js写的一个HashMap

    1.脚本 /** * 模拟HashMap */ function HashMap(){ //定义长度 var length = 0; //创建一个对象 var obj = new Object(); ...

  10. koa 核心源码介绍

    链接来源 Request,Context,Response  在代码运行之前就已经存在的 Request和Response自身的方法会委托到Context中. Context源码片段 var dele ...