zoukankan      html  css  js  c++  java
  • Repeater控件分页例子

    Repeater控件分页例子

    Repeater和DataList控件提供了一个快速、灵活的表现数据的方式,但是,它们没有内建的分页功能;DataGrid控件提供了内建的分页功能,但它的结构比较复杂。下面就用PagedDataSource类实现Repeater和DataList的分页。 PagedDataSource封装了DataGrid的分页属性,我们可以象DataGrid那样进行分页。代码如下:

    <%@ Page Language="C#" %> <%@ import namespace="System.Data" %> <%@ import namespace="System.Data.OleDb" %> <script language="C#" runat="server"> public void Page_Load(Object src,EventArgs e) { OleDbConnection objConn=new OleDbConnection("<br> Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + Server.MapPath("../aspxWeb.mdb")); OleDbDataAdapter objCommand=new OleDbDataAdapter("select * from<br> Document",objConn); DataSet ds=new DataSet();objCommand.Fill(ds); PagedDataSource objPds = new PagedDataSource(); objPds.DataSource = ds.Tables[0].DefaultView; objPds.AllowPaging = true; objPds.PageSize = 5; int CurPage; if (Request.QueryString["Page"] != null) CurPage=Convert.ToInt32(Request.QueryString["Page"]); else CurPage=1; objPds.CurrentPageIndex = CurPage-1; lblCurrentPage.Text = "当前页:" + CurPage.ToString(); if (!objPds.IsFirstPage) lnkPrev.NavigateUrl=Request.CurrentExecutionFilePath + <br> "?Page=" + Convert.ToString(CurPage-1); if (!objPds.IsLastPage) lnkNext.NavigateUrl=Request.CurrentExecutionFilePath+ "<br> ?Page=" + Convert.ToString(CurPage+1); Repeater1.DataSource=objPds; Repeater1.DataBind(); } </script> <html> <head> <title>Repeater控件分页的例子</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <style> P,TD,DIV,SPAN {font-size:9pt} </style> </head> <body> <form name="form1" method="POST" runat="server"> <div style="padding:5px;background-color:#dedede"> <asp:label ID="lblCurrentPage" runat="server"></asp:label></td> <td> <asp:HyperLink id="lnkPrev" runat="server">上一页</asp:HyperLink> <asp:HyperLink id="lnkNext" runat="server">下一页</asp:HyperLink> </div> <hr size="1" color="#000099"/> <asp:Repeater ID="Repeater1" runat="server"> <Itemtemplate> <div style="padding:5px;background-color:#dedede"> <%# DataBinder.Eval(Container.DataItem, "Title") %> </div> </itemtemplate> </asp:Repeater> </form> </body> </html>
  • 相关阅读:
    C# WinForm开发系列 Socket/WCF/Rometing/Web Services
    .net(c#) 简单的软件注册功能的实现:
    来自xici网友的Ubuntu和windows xp的Super PI性能测试
    最新的Linpack测试指南-基于woodcrest机器
    CFX x86_64 version issues 无法找到可执行文件
    如何检查一个mvapich的版本?
    Intel Tools Training Notes Intel Compiler, MKLs
    Infiniband IPoIB Debug FAQ
    让CFX的license server在开机的时候就自动启动
    FFTW 3.1.2 和 2.1.5编译
  • 原文地址:https://www.cnblogs.com/YrRoom/p/310854.html
Copyright © 2011-2022 走看看