标题:请分析我这个Repeater分页代码哪里出问题了?
取消只看楼主
cydesign
Rank: 1
等 级:新手上路
帖 子:134
专家分:0
注 册:2006-11-2
 问题点数:0 回复次数:2 
请分析我这个Repeater分页代码哪里出问题了?

页面代码:

<%@ 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
}
}


出现的问题是:点击下一页数据得不到更新。请帮忙看看是哪里出问题了?谢谢!

搜索更多相关主题的帖子: Repeater 代码 
2006-11-19 23:13
cydesign
Rank: 1
等 级:新手上路
帖 子:134
专家分:0
注 册:2006-11-2
得分:0 
以下是引用bygg在2006-11-20 11:50:09的发言:
lnkPrev.NavigateUrl=Request.CurrentExecutionFilePath+"?Page="+Convert.ToString(CurPage-1);

2006-11-21 22:29
cydesign
Rank: 1
等 级:新手上路
帖 子:134
专家分:0
注 册:2006-11-2
得分:0 

非常感谢!

2006-11-22 17:33



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-104105-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.351745 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved