repeater分页的实现
来源:互联网 发布:淘宝和京东创始人 编辑:程序博客网 时间:2024/04/28 22:32
第一种方式:数据库连接代码:01using System;02using System.Data;03using System.Configuration;04using System.Web;05using System.Web.Security;06using System.Web.UI;07using System.Web.UI.WebControls;08using System.Web.UI.WebControls.WebParts;09using System.Web.UI.HtmlControls;10using System.Data.SqlClient;11using System.Data.Sql;12131415public partial class _Default : System.Web.UI.Page16{17 private void con()18 {19 string connstring = ConfigurationManager.ConnectionStrings["AdventureWorksDWConnectionString"].ConnectionString;20 SqlConnection con = new SqlConnection(connstring);21 SqlConnection conn = new SqlConnection();22 DataSet ds = new DataSet();23 SqlDataAdapter sda = new SqlDataAdapter("select * from FactSalesQuota", con);24 sda.Fill(ds, "name");25 SqlDataAdapter sda2 = new SqlDataAdapter("select * from ProspectiveBuyer", con);26 sda2.Fill(ds, "title");27 PagedDataSource pds = new PagedDataSource();28 pds.DataSource = ds.Tables["name"].DefaultView;29 //PagedDataSource aa = new PagedDataSource();30 pds.AllowPaging = true;//允许分页31 pds.PageSize = 8;//单页显示项数32 int CurPage;33 if (Request.QueryString["Page"] != null)34 CurPage = Convert.ToInt32(Request.QueryString["Page"]);35 else36 CurPage = 1;37 pds.CurrentPageIndex = CurPage - 1;38 int Count = pds.PageCount;3940 lblCurrentPage.Text = "当前页:" + CurPage.ToString();41 labPage.Text = Count.ToString();4243 if (!pds.IsFirstPage)44 {45 this.first.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=1";46 this.last.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(Count - 1); ;47 up.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage - 1);48 }49 else50 {51 this.first.Visible = false ;52 this.last.Visible = false ;53 54 }5556 if (!pds.IsLastPage)57 {58 59 60 next.NavigateUrl = Request.CurrentExecutionFilePath + "?Page=" + Convert.ToString(CurPage + 1);61 }62 else63 {64 this.first.Visible = false;65 this.last.Visible = false;6667 }6869 Repeater1.DataSource = pds ;70 Repeater1.DataBind();7172 }73747576 protected void Page_Load(object sender, EventArgs e)77 {78 if (!IsPostBack)79 {80 con();81 this.first.Visible = true;82 this.last.Visible = true;83 //this.Repeater1.DataSource = pds();84 //this.Repeater1.DataBind();8586 }8788 }89} aspx文件代码:01<table>02 <tr ><td class="style1" align ="left" >hehe</td></tr>03 04 <tr ><td class="style1"> 05 <asp:Repeater ID="Repeater1" runat="server" >06 07 <HeaderTemplate ><table><tr><td>头模板</td></tr></HeaderTemplate>08 <ItemTemplate ><tr><td ><font color="red" > <%#Eval("timekey")%></font></td></tr></ItemTemplate>09 <AlternatingItemTemplate ><tr><td > <a href ='Default.aspx?id=<%#"databaselogid" %>'><%#Eval("SalesAmountQuota")%></a></td></tr></AlternatingItemTemplate>10 <FooterTemplate ><tr><td>尾模板</td></tr></table></FooterTemplate>11 </asp:Repeater>12 </td> </tr>13 14 15 <tr> <td class="style1">16 <asp:HyperLink ID="first" runat="server">首页</asp:HyperLink>17 <asp:HyperLink ID="next" runat="server">下一页</asp:HyperLink>18 <asp:HyperLink ID="up" runat="server">上一页</asp:HyperLink>19 <asp:HyperLink ID="last" runat="server">末页</asp:HyperLink>20 </td></tr>21 22 <tr><td class="style1">当前页为:<asp:Label ID="lblCurrentPage" runat="server"23 Text="Label"></asp:Label>24 <br />25 共<asp:Label ID="labPage" runat="server" Text="Label"></asp:Label>26 页</td></tr>27 28</table>第二种方式:01using System;02using System.Collections;03using System.Configuration;04using System.Data;05using System.Linq;06using System.Web;07using System.Web.Security;08using System.Web.UI;09using System.Web.UI.HtmlControls;10using System.Web.UI.WebControls;11using System.Web.UI.WebControls.WebParts;12using System.Xml.Linq;13using System.Data.SqlClient;1415public partial class databind : System.Web.UI.Page16{17 18 protected void Page_Load(object sender, EventArgs e)19 {20 if (!IsPostBack)21 {22 num.Text = "1";23 repdatabind();24 }252627 }28 public void repdatabind()29 {30 string connstring = ConfigurationManager.ConnectionStrings["AdventureWorksDWConnectionString"].ConnectionString;31 SqlConnection con = new SqlConnection(connstring);32 SqlConnection conn = new SqlConnection();33 DataSet ds = new DataSet();34 SqlDataAdapter sda = new SqlDataAdapter("select * from DimProduct", con);35 sda.Fill(ds, "name");36 PagedDataSource pds = new PagedDataSource();37 pds.DataSource = ds.Tables["name"].DefaultView;38 pds.AllowPaging = true;//允许分页39 pds.PageSize = 8;//单页显示项数4041 int curpage = Convert.ToInt32(num.Text);42 this.BtnDown.Enabled = true;43 this.BtnUp.Enabled = true;44 pds.CurrentPageIndex = curpage - 1;45 if (curpage == 1)46 {47 this.BtnUp.Enabled = false;48 }49 if (curpage == pds.PageCount)50 {51 this.BtnDown.Enabled = false;52 }53 this.Repeater1.DataSource = pds;54 this.Repeater1.DataBind();55 }56 57 protected void BtnUp_Click(object sender, EventArgs e)58 {59 this.num.Text =Convert.ToString ( Convert.ToInt32(num.Text)- 1) ;60 repdatabind();61 }62 protected void BtnDown_Click(object sender, EventArgs e)63 {64 this.num.Text = Convert.ToString(Convert.ToInt32(num.Text)+ 1) ;65 repdatabind();66 }67}aspx代码:01<%@ Page Language="C#" AutoEventWireup="true" CodeFile="databind.aspx.cs" Inherits="databind"%>0203<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">0405<html xmlns="http://www.w3.org/1999/xhtml">06<head runat="server">07 <title>无标题页</title>08</head>09<body>10 <form id="form1" runat="server">11 <div>12 13 <asp:Panel ID="Panel1" runat="server" Height="173px">14 <asp:Repeater ID="Repeater1" runat="server"><HeaderTemplate ><table border onmousedown="1" ><tr><td >头模板</td></tr></HeaderTemplate><ItemTemplate ><tr><td>序号:<%# Eval("ProductKey") %></td></tr><tr><td>编码:<%# Eval("ProductAlternateKey") %></td></tr></ItemTemplate><FooterTemplate ><tr><td>脚模板</td></tr></table>< /FooterTemplate>15 </asp:Repeater>16 当前页:<asp:Label ID="num" runat="server"></asp:Label>17 <br />18 <asp:Button ID="BtnUp" runat="server" onclick="BtnUp_Click" Text="上一页" />19 <asp:Button ID="BtnDown" runat="server" onclick="BtnDown_Click" Text="下一页" />20 </asp:Panel>21 <br />22 <br />23 24 </div>25 </form>26</body>27</html>
0 0
- repeater分页的实现
- repeater分页的实现
- repeater分页的实现
- repeater分页的实现
- Repeater控件的分页实现
- 如何实现Repeater控件的分页
- Repeater控件分页功能的实现
- 实现 DataList 或 Repeater 控件的分页
- 用存储过程实现Repeater的分页
- sqldataread与repeater分页的实现
- Repeater真的不能实现分页吗?
- Repeater实现分页
- Repeater控件实现分页
- repeater控件实现分页
- repeater控件实现分页
- repeater控件实现分页
- repeater控件实现分页
- Repeater的分页代码
- ASP.NET常用方法
- 数据结构实验之栈一:进制转换(栈的应用)
- 在Eclipse Java EE中安装 Emmet (Zend Coding) 需要注意的地方!
- oracle 与Access的区别
- zoj 3816 2014牡丹江网赛 DFS
- repeater分页的实现
- 深圳福佳白啤酒加盟代理批发
- Starling Feathers Controls ScreenNavigator
- JAVA编程思想-第九章 接口
- [切图]不规则图形的切法
- swift UINavigationController 导航控制器(六)【转自http://blog.csdn.net/zhang_biao_1991/article/details/313927】
- logmnr使用
- 黑马程序员--【学习日记三】——java面向对象(一)
- SEH处理