Example of pagination for repeater controls

Source: Internet
Author: User
Tags tostring
Page Pagination | control

Repeater and DataList controls provide a quick, flexible way to represent data, but they do not have built-in paging functionality; The DataGrid control provides built-in paging functionality, but its structure is more complex. Here's how to implement Repeater and DataList pagination with the PagedDataSource class. PagedDataSource encapsulates the paging properties of the DataGrid, and we can page pagination like the DataGrid. The code is as follows:

<%@ 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 ("Provider=Microsoft.Jet.OLEDB.4.0; Data source= "+
Server.MapPath (".. /aspxweb.mdb "));
OleDbDataAdapter objcommand=new OleDbDataAdapter ("SELECT * from 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 = "Current page:" + curpage.tostring ();

if (!objpds.isfirstpage)
Lnkprev.navigateurl=request.currentexecutionfilepath + "? Page= "+ convert.tostring (CurPage-1);

if (!objpds.islastpage)
Lnknext.navigateurl=request.currentexecutionfilepath+ "? Page= "+ convert.tostring (curpage+1);

Repeater1.datasource=objpds;
Repeater1.databind ();
}
</script>
Examples of pagination for <title>repeater controls </title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<style>
P,td,div,span {font-size:9pt}
</style>
<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" > previous page </asp:HyperLink>
<asp:hyperlink id= "Lnknext" runat= "Server" > next page </asp:HyperLink>
</div>
&LT;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>



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.