|
There are many pages on the Repeater control, but they are paged when the page loads, as in the following example:
<% @ 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>
<html>
<head>
<title> Example of Repeater Control Pagination </ 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"> 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>
</ html>
In practical applications, they are based on a certain event (such as a query). If the above example is rewritten as Repeater paging based on a certain query event? |
|