<%@ Page language="c#" Codebehind="WebForm2.aspx.cs" AutoEventWireup="false" Inherits="Shop.WebForm2" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>Repeater控件分頁的例子PagedDataSource</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<!--<meta http-equiv="Content-Type" content="text/html; charset=gb2312">-->
<style>
P { FONT-SIZE: 9pt }
TD { FONT-SIZE: 9pt }
DIV { FONT-SIZE: 9pt }
SPAN { FONT-SIZE: 9pt }
</style>
</HEAD>
<body>
<form name="form1" method="post" runat="server" ID="Form1">
<div style="PADDING-RIGHT:5px;PADDING-LEFT:5px;PADDING-BOTTOM:5px;PADDING-TOP: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, "CPMNO") %>
</div>
<div style="padding:5px;background-color:#dedede">
<%# DataBinder.Eval(Container.DataItem, "P_nick_name") %>
</div>
</Itemtemplate>
</asp:Repeater>
</form>
</body>
</HTML>
***********************************************************************
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using MyConfig;
using Microsoft.ApplicationBlocks.Data;
using System.Diagnostics;
namespace Shop
{
/// <summary>
/// WebForm2 的摘要描述。
/// </summary>
public class WebForm2 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label lblCurrentPage;
protected System.Web.UI.WebControls.HyperLink lnkPrev;
protected System.Web.UI.WebControls.HyperLink lnkNext;
protected System.Web.UI.WebControls.Repeater Repeater1;
private void Page_Load(object sender, System.EventArgs e)
{
// 在這裡放置使用者程式碼以初始化網頁
// OleDbDataAdapter objCommand=new OleDbDataAdapter("select * from Document",objConn);
DataSet ds=new DataSet();
ds = SqlHelper.ExecuteDataset(MyConfig.MyConfigSectionHandler.ConnectionString,CommandType.Text,"select * from people");
//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 + "?Page=" + Convert.ToString(CurPage-1);
if (!objPds.IsLastPage)
lnkNext.NavigateUrl=Request.CurrentExecutionFilePath+ "?Page=" + Convert.ToString(CurPage+1);
Repeater1.DataSource=objPds;
Repeater1.DataBind();
}
#region Web Form 設計工具產生的程式碼
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 此為 ASP.NET Web Form 設計工具所需的呼叫。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 此為設計工具支援所必須的方法 - 請勿使用程式碼編輯器修改
/// 這個方法的內容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}