62,074
社区成员
发帖
与我相关
我的任务
分享
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>