<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. JavaScript学习总结(五)——Javascript中==和===的区别

    一.JavaScript"=="的作用 当==两边的内容是字符串时,则比较字符串的内容是否相等. 当==两边的内容是数字时,则比较数字的大小是否相等. 当==两边的内容是对象或者是 ...

  2. memory prefix un,under,uni out1

    1● un 不 非,无 打开 ,解开 ,开出     2● under ʌnd ə 向下,副 的,不足的   3● uni   单一 ,单  

  3. jenkins+git+docker实验环境的搭建

    持续集成(c/i)的实验环境 git/harbor服务器    ip 192.168.200.132 docker服务器          ip 192.168.200.149 Jenkins服务器 ...

  4. 使用API接口在zabbix系统中登陆、创建、删除agent

    一.API的介绍 API(Application Programming Interface,应用程序编程接口)是一些预先定义的函数,目的是提供应用程序与开发人员基于某软件或硬件得以访问一组例程的能力 ...

  5. websevice之三要素

    SOAP(Simple Object Access Protocol).WSDL(WebServicesDescriptionLanguage).UDDI(UniversalDescriptionDi ...

  6. 推荐两个Magento做的中文网站 GAP和佰草集

    Magento这两年发展很快,可以算是现阶段最有前途的开源电子商务系统,国外用的人很多,相对应的,国内也已经有很多人在用Magento建站了,可惜的是这其中绝大多数还是英文站,大多是国内外贸商建的外贸 ...

  7. matplotlib.pyplot中add_subplot方法参数111的含义

    下述代码若要运行,得在安装Python之外安装matplotlib.numpy.scipy.six等库,专门来看这篇小贴的朋友应该知道这些库. 参数331的意思是:将画布分割成3行3列,图像画在从左到 ...

  8. HDU 1024:Max Sum Plus Plus(DP,最大m子段和)

    Max Sum Plus Plus Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...

  9. Knight Tournament 合并区间

    Hooray! Berl II, the king of Berland is making a knight tournament. The king has already sent the me ...

  10. hdu1255 覆盖的面积 线段树-扫描线

    矩形面积并 线段树-扫描线裸题 #include<stdio.h> #include<string.h> #include<algorithm> #include& ...