页面代码:
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication5.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<table id="Table1" border="0">
<tr>
<td align="right">
<asp:Label ID="lblCurPage" Runat="server"></asp:Label>
<asp:HyperLink ID="lnkPrev" Runat="server">上一页</asp:HyperLink>
<asp:HyperLink ID="lnkNext" Runat="server">下一页</asp:HyperLink></td>
</tr>
<tr>
<td>
<hr color="red" size="1">
<asp:Repeater ID="RepeaterPage" runat="server">
<ItemTemplate>
<li>
<%#DataBinder.Eval(Container.DataItem,"subjects")%>
<%#DataBinder.Eval(Container.DataItem,"sysdate")%>
<%#DataBinder.Eval(Container.DataItem,"author")%>
</li>
</ItemTemplate>
</asp:Repeater></td>
</tr>
</table>
<FONT face="宋体"></FONT>
</form>
</body>
</HTML>
后台代码
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Data.OleDb;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace WebApplication5
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label lblCurPage;
protected System.Web.UI.WebControls.HyperLink lnkPrev;
protected System.Web.UI.WebControls.HyperLink lnkNext;
protected System.Web.UI.WebControls.Repeater RepeaterPage;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!IsPostBack)
RepeaterDataBind();
}
private void RepeaterDataBind()
{
SqlConnection conn=new SqlConnection("Data source=localhost;uid=sa;pwd=sa;Initial Catalog=news");
SqlDataAdapter da=new SqlDataAdapter("select subjects,sysdate,author from news",conn);
DataSet ds=new DataSet();
try
{
da.Fill(ds,"TestTable");
PagedDataSource objPage=new PagedDataSource();
objPage.DataSource=ds.Tables["TestTable"].DefaultView;
objPage.AllowPaging=true;
objPage.PageSize=5;
int CurPage;
if(Request.QueryString["Page"]!=null)
CurPage=Convert.ToInt32(Request.QueryString["Page"]);
else
CurPage=1;
objPage.CurrentPageIndex=CurPage-1;
lblCurPage.Text="当前页:第"+CurPage.ToString()+"页";
if(!objPage.IsFirstPage)
lnkPrev.NavigateUrl=Request.CurrentExecutionFilePath+"?Page"+Convert.ToString(CurPage-1);
if(!objPage.IsLastPage)
lnkNext.NavigateUrl=Request.CurrentExecutionFilePath+"?Page"+Convert.ToString(CurPage+1);
RepeaterPage.DataSource=objPage;
RepeaterPage.DataBind();
}
catch(Exception error)
{
Response.Write(error.ToString());
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
出现的问题是:点击下一页数据得不到更新。请帮忙看看是哪里出问题了?谢谢!