Repeater 如何分页!

SB12342 2011-04-14 03:00:01
public DataTable bt=new DataTable();

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
localhost.Service WebserviceInstance = new localhost.Service();
localhost.SecurityHeader header = new localhost.SecurityHeader();
header.username = "111";
header.password = "222";
header.key = "333";
WebserviceInstance.SecurityHeaderValue = header;
WebserviceInstance.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
int a=0;
int b=0;
string xmldler="<root><derept id="+a+"></derept><sdert id="+b+"></sdert>";
DataSet retn = WebserviceInstance.GetMoSMSInfo(xmldler);
}
}
/// <summary>
/// 解析xml
/// </summary>
/// <param name="xmlDeliver"></param>
public void DeliverSMS(string xmlDeliver)
{
string dptName = "";
string sdptName = "";
string UserName = "";
string phone1 = "";
string content1 = "";
string time1 = "";
XmlDataDocument smsdle = new XmlDataDocument();
smsdle.LoadXml(xmlDeliver);
XmlNode nodleSMS = smsdle.SelectSingleNode("root");
XmlNodeList nodldle = nodleSMS.ChildNodes;
foreach (XmlNode xd in nodldle)
{
XmlElement xet = (XmlElement)xd;
if (xet.Name.Equals(""))
{ dptName = xet.InnerText; }
if (xet.Name.Equals(""))
{
sdptName = xet.InnerText;
}
if (xet.Name.Equals(" "))
{
UserName = xet.InnerText;
}
if (xet.Name.Equals(""))
{
phone1 = xet.InnerText;
}
if (xet.Name.Equals(""))
{
content1 = xet.InnerText;
}
if (xet.Name.Equals(" "))
{
time1 = xet.InnerText;
}
bt.Columns.Add("dptName");
bt.Columns.Add("sdptName");
bt.Columns.Add("UserName");
bt.Columns.Add("phone1");
bt.Columns.Add("content1");
bt.Columns.Add("time1");
}
}
怎么分页 我的页面前台是一个Repeater。
...全文
354 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
子夜__ 2011-04-14
  • 打赏
  • 举报
回复
SB12342 2011-04-14
  • 打赏
  • 举报
回复
protected void Page_Load(object sender, EventArgs e)
{
repetpaging();
}

private void repetpaging()
{
SqlConnection conn = new SqlConnection(strconn);
conn.Open();
string sql = "select *from SMS_Deliver ";
SqlDataAdapter adp = new SqlDataAdapter(sql, conn);
DataSet ds = new DataSet();

adp.Fill(ds, "Deliver");
PagedDataSource pdds = new PagedDataSource();
pdds.DataSource = ds.Tables["Deliver"].DefaultView;

pdds.DataSource = ds.Tables["Deliver"].DefaultView;
pdds.AllowPaging = true;
pdds.PageSize = 5;
pdds.CurrentPageIndex = Convert.ToInt32(this.labPage.Text) - 1;

rpt.DataSource = pdds;
this.labTotal.Text = pdds.PageCount.ToString();
labPage.Text = (pdds.CurrentPageIndex + 1).ToString();
this.bt_sy.Enabled = true;
this.bt_syy.Enabled = true;
this.bt_wy.Enabled = true;
this.bt_xyy.Enabled = true;
if (pdds.CurrentPageIndex < 1)
{
this.bt_syy.Enabled = false;
this.bt_sy.Enabled = false;
}
if (pdds.CurrentPageIndex == pdds.Count - 1)
{
this.bt_wy.Enabled = false;
this.bt_xyy.Enabled = false;
}
rpt.DataBind();
conn.Close();
}
protected void bt_sy_Click(object sender, EventArgs e)
{
labPage.Text = "1";
repetpaging();
}
protected void bt_syy_Click(object sender, EventArgs e)
{
labPage.Text = Convert.ToString(Convert.ToInt32(labPage.Text)-1);
repetpaging();
}
protected void bt_xyy_Click(object sender, EventArgs e)
{
labPage.Text = Convert.ToString(Convert.ToInt32(labPage.Text)+1);
repetpaging();
}
protected void bt_wy_Click(object sender, EventArgs e)
{
labPage.Text = this.labTotal.Text;
repetpaging();
}

我这样写能实现分页 但是我的项目中数据是从webservice中传过来的XML组合 不能去操作数据库
SB12342 2011-04-14
  • 打赏
  • 举报
回复
未将对象引用设置到对象的实例。
ycproc 2011-04-14
  • 打赏
  • 举报
回复
http://www.webdiyer.com/Controls/AspNetPager

这个分页的 控件 推荐给你

我觉得 还是 用分页控件 开始比较好

你自己写一个更好了
其实也没什么的
ycproc 2011-04-14
  • 打赏
  • 举报
回复
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class a9 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DataListBind();//注意不能写在 if (!IsPostBack)里那样回传时就不会调用这个函数了,点击就不管作用了
}
public void DataListBind()
{
PagedDataSource objpage = new PagedDataSource();
Book dlBook = new Book();
objpage.DataSource = dlBook.dsBook("select * from books").Tables[0].DefaultView;
objpage.AllowPaging = true;
objpage.PageSize = 2;
int curpage;
if (Request.QueryString["Page"] != null)
{
curpage = Convert.ToInt32(Request.QueryString["Page"]);
}
else
{
curpage = 1;
}
objpage.CurrentPageIndex = curpage - 1;
if (objpage.IsFirstPage && objpage.IsLastPage)
{
this.LBfirst.Enabled = false;
this.LBpre.Enabled = false;
this.LBnext.Enabled = false;
this.LBlast.Enabled = false;
}
else
{
if (objpage.IsFirstPage && !objpage.IsLastPage)
{
this.LBfirst.Enabled = false;
this.LBpre.Enabled = false;
this.LBnext.Enabled = true;
this.LBlast.Enabled = true;
this.LBnext.PostBackUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToInt32(curpage + 1);
this.LBlast.PostBackUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToInt32(objpage.PageCount);
}
else
{
if (objpage.IsLastPage && !objpage.IsFirstPage)
{
this.LBfirst.Enabled = true;
this.LBpre.Enabled = true;
this.LBnext.Enabled = false;
this.LBlast.Enabled = false;
this.LBfirst.PostBackUrl = Request.CurrentExecutionFilePath + "?Page=" + 1;
this.LBpre.PostBackUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToInt32(curpage - 1);
}
else
{
this.LBfirst.Enabled = true;
this.LBpre.Enabled = true;
this.LBnext.Enabled = true;
this.LBlast.Enabled = true;
this.LBfirst.PostBackUrl = Request.CurrentExecutionFilePath + "?Page=" + 1;
this.LBpre.PostBackUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToInt32(curpage - 1);
this.LBnext.PostBackUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToInt32(curpage + 1);
this.LBlast.PostBackUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToInt32(objpage.PageCount);
}
}
}
this.Repeater1.DataSource = objpage;
this.Repeater1.DataBind();
}
}


Repeater分页 收藏
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class a9 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DataListBind();//注意不能写在 if (!IsPostBack)里那样回传时就不会调用这个函数了,点击就不管作用了
}
public void DataListBind()
{
PagedDataSource objpage = new PagedDataSource();
Book dlBook = new Book();
objpage.DataSource = dlBook.dsBook("select * from books").Tables[0].DefaultView;
objpage.AllowPaging = true;
objpage.PageSize = 2;
int curpage;
if (Request.QueryString["Page"] != null)
{
curpage = Convert.ToInt32(Request.QueryString["Page"]);
}
else
{
curpage = 1;
}
objpage.CurrentPageIndex = curpage - 1;
if (objpage.IsFirstPage && objpage.IsLastPage)
{
this.LBfirst.Enabled = false;
this.LBpre.Enabled = false;
this.LBnext.Enabled = false;
this.LBlast.Enabled = false;
}
else
{
if (objpage.IsFirstPage && !objpage.IsLastPage)
{
this.LBfirst.Enabled = false;
this.LBpre.Enabled = false;
this.LBnext.Enabled = true;
this.LBlast.Enabled = true;
this.LBnext.PostBackUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToInt32(curpage + 1);
this.LBlast.PostBackUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToInt32(objpage.PageCount);
}
else
{
if (objpage.IsLastPage && !objpage.IsFirstPage)
{
this.LBfirst.Enabled = true;
this.LBpre.Enabled = true;
this.LBnext.Enabled = false;
this.LBlast.Enabled = false;
this.LBfirst.PostBackUrl = Request.CurrentExecutionFilePath + "?Page=" + 1;
this.LBpre.PostBackUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToInt32(curpage - 1);
}
else
{
this.LBfirst.Enabled = true;
this.LBpre.Enabled = true;
this.LBnext.Enabled = true;
this.LBlast.Enabled = true;
this.LBfirst.PostBackUrl = Request.CurrentExecutionFilePath + "?Page=" + 1;
this.LBpre.PostBackUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToInt32(curpage - 1);
this.LBnext.PostBackUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToInt32(curpage + 1);
this.LBlast.PostBackUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToInt32(objpage.PageCount);
}
}
}
this.Repeater1.DataSource = objpage;
this.Repeater1.DataBind();
}
}

----------------------------------------------------------
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="a9.aspx.cs" Inherits="a9" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<%# Eval("BookName") %>
</ItemTemplate>
</asp:Repeater>

</div>
<asp:LinkButton ID="LBfirst" runat="server" CommandArgument="first">首页</asp:LinkButton>
<asp:LinkButton ID="LBpre" runat="server">上一页</asp:LinkButton>
<asp:LinkButton ID="LBnext" runat="server">下一页</asp:LinkButton>
<asp:LinkButton ID="LBlast" runat="server">尾页</asp:LinkButton>
</form>
</body>
</html>
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 sb12342 的回复:]

你给它绑定数据源的时候就只绑定固定的数量 这种方法不让我用

前面两个的都有个
pds.DataSource = ds.Tables["name"].DefaultView;
这个要出异常
[/Quote]
不固定就用参数不就完了。什么异常,贴出来。
下班了。。回去有时间看看。
SB12342 2011-04-14
  • 打赏
  • 举报
回复
你给它绑定数据源的时候就只绑定固定的数量 这种方法不让我用

前面两个的都有个
pds.DataSource = ds.Tables["name"].DefaultView;
这个要出异常
wcfboy1 2011-04-14
  • 打赏
  • 举报
回复
PagedDataSource 1楼就可以
fire_fire_fire 2011-04-14
  • 打赏
  • 举报
回复
你给它绑定数据源的时候就只绑定固定的数量,比如10条,然后放个asp.netpage分页控件,每次点击分页控件的时候就调用一个方法,在方法里面重新取一次数据并且重新绑定repeater就可以了
小童 2011-04-14
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 mockqi 的回复:]
PagedDataSource pds = new PagedDataSource();
pds.DataSource = ds.Tables["name"].DefaultView;
//PagedDataSource aa = new PagedDataSource();
pds.AllowPaging = true;//允许分页
pds.PageSize = 10……
[/Quote]+
  • 打赏
  • 举报
回复

PagedDataSource pds = new PagedDataSource();
pds.DataSource = ds.Tables["name"].DefaultView;
//PagedDataSource aa = new PagedDataSource();
pds.AllowPaging = true;//允许分页
pds.PageSize = 10;//单页显示项数
int CurPage;
if (Request.QueryString["Page"] != null)
CurPage = Convert.ToInt32(Request.QueryString["Page"]);
else
CurPage = 1;
pds.CurrentPageIndex = CurPage - 1;
int Count = pds.PageCount;

lblCurrentPage.Text = "当前页:" + CurPage.ToString();
labPage.Text = Count.ToString();

if (!pds.IsFirstPage)
{
this.first.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=1";
this.last.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(Count - 1); ;
up.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage - 1);
}
else
{
this.first.Visible = false ;
this.last.Visible = false ;

}

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧