| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 586 人关注过本帖
标题:请分析我这个Repeater分页代码哪里出问题了?
只看楼主 加入收藏
cydesign
Rank: 1
等 级:新手上路
帖 子:134
专家分:0
注 册:2006-11-2
收藏
 问题点数:0 回复次数:6 
请分析我这个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
メ冰枫ぱ雪
Rank: 1
等 级:新手上路
威 望:2
帖 子:326
专家分:0
注 册:2004-11-13
收藏
得分:0 
If(!Page.IsPostBack) 这句的作用你去查查先就知道啦。。!

动态网页技术交流群:16449874 免费网络收藏夹:http:///Favorite
2006-11-20 00:12
hoya
Rank: 5Rank: 5
等 级:贵宾
威 望:15
帖 子:538
专家分:0
注 册:2006-6-27
收藏
得分:0 
lnkPrev.NavigateUrl=Request.CurrentExecutionFilePath+"?Page"+Convert.ToString(CurPage-1);


你试着检查看看这句有没问题... 参数

妈的...一天能卖一颗就很不错了...
2006-11-20 08:49
lian8088
Rank: 1
等 级:新手上路
威 望:1
帖 子:101
专家分:0
注 册:2006-8-21
收藏
得分:0 
没有给HyperLink写事件

2006-11-20 11:21
bygg
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:乖乖的心中
等 级:版主
威 望:241
帖 子:13555
专家分:3076
注 册:2006-10-23
收藏
得分:0 
lnkPrev.NavigateUrl=Request.CurrentExecutionFilePath+"?Page="+Convert.ToString(CurPage-1);

飘过~~
2006-11-20 11:50
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
快速回复:请分析我这个Repeater分页代码哪里出问题了?
数据加载中...
 
   



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

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