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 ...
随机推荐
- Intellij Idea配置提高速度
主要介绍一下Intellij Idea的关于速度和最大最大方法数目 提高速度 1.命令: 2.找到./Library/Preferences/IntelliJIdea2016.1/idea.vmopt ...
- 通过iframe引入另外一个项目中的html片段到项目中,解决样式,高度,兼容等问题的策略
<!--尾部开始--> <iframe src="http://172.16.24.11:9000/cartoon-web/footer_new" m ...
- Android官方技术文档翻译——Gradle 插件用户指南(4)
最近赶项目,白天基本没时间,只有晚上在家的时候才能看一看.昨天晚上只翻译完了第四章,今天就只发第四章吧. 本文译自Android官方技术文档<Gradle Plugin User Guide&g ...
- 017-封装-OC笔记
学习目标 1.[了解]异常处理 2.[掌握]类方法 3.[掌握]NSString类 4.[掌握]匿名对象 5.[掌握]封装实例变量 6.[掌握]对象之间的关系 一.异常处理 什么是异常? 代码完全符合 ...
- 【Android 应用开发】 Ubuntu 安装 Android Studio (旧版本|仅作参考)
. 果断换Ubuntu了, Ubuntu的截图效果不好, 不能设置阴影 ... 作者 : 万境绝尘 转载请注明出处 : http://blog.csdn.net/shulianghan/article ...
- 【linux学习笔记】在ubuntu下使用QT Cmake支持C++11
今天在ubuntu下使用QT来进行C++编程,选择了Cmake,当用到initializer_list的时候提示不支持C++11,现提供一下解决方案: 错误提示: error: This file r ...
- java面试之常见编程题
1.编程实现:二分搜索算法 解答: public class SearchTest { /** 被搜索数据的大小 */ private static final int size = 5000000; ...
- 俺的新书《Sencha Touch实战》终于出版了
内容简介:Sencha框架是第一个基于HTML 5的移动也能给予框架,可以让Web应用看起来像网络应用.美丽的用户 界面 组件和丰富的数据管理,全部基于最新的HTML 5和CSS 3的Web标准,全部 ...
- FPGrowth
在挖掘关联规则的过程中,无可避免要处理海量的数据,也就是事务数据库如此之大,如果采用Apriori算法来挖掘,每次生成频繁k-项集的时候,可能都需要扫描事务数据库一遍,这是非常耗时的操作.那么,可以想 ...
- Android群英传笔记——第五章:Android Scroll分析
Android群英传笔记--第五章:Android Scroll分析 滑动事件算是Android比较常用的效果了,而且滑动事件他本身也是有许多的知识点,今天,我们就一起来耍耍Scroll吧 一.滑动效 ...