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>
<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>