ASP.NET(C#) Repeater分页的实现
第一种方式:
数据库连接代码:
using System;
using System.Data;
using System.Configuration;
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;
using System.Data.Sql;
public partial class _Default : System.Web.UI.Page
{
private void con()
{
SqlConnection con = new SqlConnection("server='.';database=test;uid=sa;pwd=123456;");
SqlConnection conn = new SqlConnection();
DataSet ds = new DataSet();
SqlDataAdapter sda = new SqlDataAdapter("select * from news", con);
sda.Fill(ds, "newsTitle");
//SqlDataAdapter sda2 = new SqlDataAdapter("select * from ProspectiveBuyer", con);
// sda2.Fill(ds, "title");
PagedDataSource pds = new PagedDataSource();
pds.DataSource = ds.Tables["name"].DefaultView;
//PagedDataSource aa = new PagedDataSource();
pds.AllowPaging = true;//允许分页
pds.PageSize = 8;//单页显示项数
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 ;
}
if (!pds.IsLastPage)
{
next.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage + 1);
}
else
{
this.first.Visible = false;
this.last.Visible = false;
}
Repeater1.DataSource = pds ;
Repeater1.DataBind();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
con();
this.first.Visible = true;
this.last.Visible = true;
//this.Repeater1.DataSource = pds();
//this.Repeater1.DataBind();
}
}
}
aspx文件代码:
<table>
<tr ><td class="style1" align ="left" >hehe</td></tr>
<tr ><td class="style1">
<asp:Repeater ID="Repeater1" runat="server" >
<HeaderTemplate ><table><tr><td>头模板</td></tr></HeaderTemplate>
<ItemTemplate ><tr><td ><font color="red" > <%#("timekey")%></font></td></tr></ItemTemplate>
<AlternatingItemTemplate ><tr><td > <a href ='Default.aspx?id=<%#"databaselogid" %>'><%#("SalesAmountQuota")%></a></td></tr></AlternatingItemTemplate>
<FooterTemplate ><tr><td>尾模板</td></tr></table></FooterTemplate>
</asp:Repeater>
</td> </tr>
<tr> <td class="style1">
<asp:HyperLink ID="first" runat="server">首页</asp:HyperLink>
<asp:HyperLink ID="next" runat="server">下一页</asp:HyperLink>
<asp:HyperLink ID="up" runat="server">上一页</asp:HyperLink>
<asp:HyperLink ID="last" runat="server">末页</asp:HyperLink>
</td></tr>
<tr> <td class="style1">当前页为:<asp:Label ID="lblCurrentPage" runat="server"
Text="Label"></asp:Label>
共<asp:Label ID="labPage" runat="server" Text="Label"></asp:Label>
页</td><td class="style1" style="height: 21px">
<asp:HyperLink ID="first" runat="server">首页</asp:HyperLink>
<asp:HyperLink ID="up" runat="server">上一页</asp:HyperLink>
<asp:HyperLink ID="next" runat="server">下一页</asp:HyperLink>
<asp:HyperLink ID="last" runat="server">末页</asp:HyperLink>
</td></tr>
</table>
第二种方式:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class databind : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
num.Text = "1";
repdatabind();
}
}
public void repdatabind()
{
SqlConnection con = new SqlConnection("server='.';database=test;uid=sa;pwd=123456;");
SqlConnection conn = new SqlConnection();
DataSet ds = new DataSet();
SqlDataAdapter sda = new SqlDataAdapter("select * from DimProduct", con);
sda.Fill(ds, "name");
PagedDataSource pds = new PagedDataSource();
pds.DataSource = ds.Tables["name"].DefaultView;
pds.AllowPaging = true;//允许分页
pds.PageSize = 8;//单页显示项数
int curpage = Convert.ToInt32(num.Text);
this.BtnDown.Enabled = true;
this.BtnUp.Enabled = true;
pds.CurrentPageIndex = curpage - 1;
if (curpage == 1)
{
this.BtnUp.Enabled = false;
}
if (curpage == pds.PageCount)
{
this.BtnDown.Enabled = false;
}
this.Repeater1.DataSource = pds;
this.Repeater1.DataBind();
}
protected void BtnUp_Click(object sender, EventArgs e)
{
this.num.Text =Convert.ToString ( Convert.ToInt32(num.Text)- 1) ;
repdatabind();
}
protected void BtnDown_Click(object sender, EventArgs e)
{
this.num.Text = Convert.ToString(Convert.ToInt32(num.Text)+ 1) ;
repdatabind();
}
}
aspx代码:
<%@ Page Language="C#" CodeFile="databind.aspx.cs" Inherits="databind" %>
<!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:Panel ID="Panel1" runat="server" Height="173px">
<asp:Repeater ID="Repeater1" runat="server"><HeaderTemplate ><table border onmousedown="1" ><tr><td >头模板</td></tr></HeaderTemplate><ItemTemplate ><tr><td>序号:<%# ("ProductKey") %></td></tr><tr><td>编码:<%# ("ProductAlternateKey") %></td></tr></ItemTemplate><FooterTemplate
><tr><td>脚模板</td></tr></table></FooterTemplate>
</asp:Repeater>
当前页:<asp:Label ID="num" runat="server"></asp:Label>
<br />
<asp:Button ID="BtnUp" runat="server" onclick="BtnUp_Click" Text="上一页" />
<asp:Button ID="BtnDown" runat="server" onclick="BtnDown_Click" Text="下一页" />
</asp:Panel>
<br />
<br />
</div>
</form>
</body>
</html>
ASP.NET(C#) Repeater分页的实现的更多相关文章
- asp.net中Repeater控件用法笔记
大家可能都对datagrid比较熟悉,但是如果在数据量大的时候,我们就得考虑使用 repeater作为我们的数据绑定控件了.Repeater控件与DataGrid (以及DataList)控件的主要区 ...
- ASP利用Recordset实现分页
<!--#INCLUDE FILE="../function/db.asp" --> <!--#INCLUDE FILE="../function/co ...
- 学习ASP.NET MVC(十一)——分页
在这一篇文章中,我们将学习如何在MVC页面中实现分页的方法.分页功能是一个非常实用,常用的功能,当数据量过多的时候,必然要使用分页.在今天这篇文章中,我们学习如果在MVC页面中使用PagedList. ...
- asp.net利用存储过程分页代码
-最通用的分页存储过程 -- 获取指定页的数据 CREATE PROCEDURE Pagination ), -- 表名 ) = '*', -- 需要返回的列 )='', -- 排序的字段名 , -- ...
- ASP.NET MVC 简单分页代码
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...
- Asp 解析 XML并分页显示
Asp 解析 XML并分页显示 Asp 解析 XML并分页显示,演示样例源代码例如以下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Tr ...
- asp.net MVC通用分页组件 使用方便 通用性强
asp.net MVC通用分页组件 使用方便 通用性强 该分页控件的显示逻辑: 1 当前页面反色突出显示,链接不可点击 2 第一页时首页链接不可点击 3 最后一页时尾页链接不可点击 4 当前页面左 ...
- Asp.net MVC 简单分页 自做简单分页
Asp.net MVC 简单分页: public static string Pager(int page,int pageSize,int total) { ...
- 自己写的一个ASP.NET服务器控件Repeater和GridView分页类
不墨迹,直接上代码 using System; using System.Collections.Generic; using System.Linq; using System.Text; usin ...
随机推荐
- 常见Css样式
css就是就是会使用文档,css2.0中文手册下载地址:http://download.csdn.net/my <!DOCTYPE html PUBLIC "-//W3C//DTD X ...
- 在python中的使用Libsvm
http://blog.csdn.net/pipisorry/article/details/38964135 LIBSVM是台湾大学林智仁(LinChih-Jen)教授等开发设计的一个简单.易于使用 ...
- SpriteBuilder给节点添加effect在32设备上发生crash
环境为 Xcode 6.4 , cocos2D 3.0.4 , SpriteBuilder 1.4.9 在给某一节点添加Effect后,运行在真机iphone4s上发生崩溃,显示为: 可以看到整个堆栈 ...
- 集群通信组件tribes之应用程序处理入口
Tribes为了更清晰更好地划分职责,它被设计成用IO层和应用层,IO层专心负责网络传输方面的逻辑处理,把接收到的数据往应用层传送,当然应用层发送的数据也是通过此IO层发送,数据传往应用层后必须要留一 ...
- 【Visual C++】游戏编程学习笔记之二:定时器的使用
本系列文章由@二货梦想家张程所写,转载请注明出处. 本文章链接:http://blog.csdn.net/terence1212/article/details/44195831 作者:ZeeCode ...
- Socket层实现系列 — getsockname()和getpeername()的实现
本文主要介绍了getsockname()和getpeername()的内核实现. 内核版本:3.6 Author:zhangskd @ csdn blog 应用层 int getsockname(in ...
- ZooKeeper 会话超时
1.会话概述 在ZooKeeper中,客户端和服务端建立连接后,会话随之建立,生成一个全局唯一的会话ID(Session ID).服务器和客户端之间维持的是一个长连接,在SESSION_TIMEOUT ...
- 和菜鸟一起学linux总线驱动之i2c死锁问题
不知不觉中已经有好几个月没有写点东西了,懒了就是懒了,说是忙着想把产品做得更好,都是借口,每天花一点时间来写点东西确实很不错,自己也坚持了很久很久,只不过今年以来,发现提高不是很大,能写的东西好少好少 ...
- 《万能数据库查询分析器》实现使用SQL语句直接高效地访问文本文件
<万能数据库查询分析器>实现使用SQL语句直接高效地访问文本文件 马根峰 (广东联合电子服务股份有限公司, 广州 510300) 摘要 用SQL语句来直接访问文本文件?是在做梦吗? ...
- leetCode之旅(5)-博弈论中极为经典的尼姆游戏
题目介绍 You are playing the following Nim Game with your friend: There is a heap of stones on the table ...