asp.net repeater手寫分頁實(shí)例代碼
更新時(shí)間:2009年05月07日 00:05:06 作者:
想用repeater實(shí)現(xiàn)手寫分頁的代碼,想自己控制各種樣式的朋友,可以用用。
復(fù)制代碼 代碼如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Model;
using System.Data.SqlClient;
using System.Data;
public partial class Test_RepeaterFENYE : System.Web.UI.Page
{
private readonly static CategoryBLL cb = new CategoryBLL();
private readonly static Category_Info cgi = new Category_Info();
int Menu_ID = 0;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindData();
}
}
private void BindData()
{
IList<Category_Info> li = cb.GetAllCategory();
if (li.Count > 0)
{
PagedDataSource pds = new PagedDataSource();
pds.DataSource = li;
pds.AllowPaging = true;
pds.PageSize =2;
int curPage;
if (Request.QueryString["page"] != null)
{
curPage = Convert.ToInt32(Request.QueryString["page"]);
}
else
{
curPage = 1;
}
pds.CurrentPageIndex = curPage - 1;
this.Repeater1.DataSource = pds;
this.Repeater1.DataBind();
this.Label4.Text = "";
this.Label4.Text += "<a>共有<font color=red><b>" + li.Count.ToString() + "</b></font>條記錄</a> ";
this.Label4.Text += "<a>每頁顯示<font color=red><b>" + pds.PageSize + "</b></font>條</a> ";
this.Label4.Text += "<a>共<font color=red><b>" + pds.PageCount.ToString() + "</b></font>頁</a> ";
this.Label4.Text += "<a>當(dāng)前第<font color=red><b>" + curPage.ToString() + "</b></font>頁</a> ";
if (curPage == 1)
{
this.Label4.Text += "<a>首頁</a> ";
this.Label4.Text += "<a>上一頁</a> ";
}
else
{
//this.Label4.Text += "<a href='wjProduct-1-" + Menu_ID + ".html'>首頁</a> ";
//this.Label4.Text += "<a href='wjProduct-" + (curPage - 1).ToString() + "-" + Menu_ID + ".html'>上一頁</a> ";
this.Label4.Text += "<a href='RepeaterFENYE.aspx'>首頁</a> ";
this.Label4.Text += "<a href='RepeaterFENYE.aspx?page="+(curPage - 1).ToString()+"'>上一頁</a> ";
}
if (curPage == pds.PageCount)
{
this.Label4.Text += "<a>下一頁</a> ";
this.Label4.Text += "<a>尾頁</a> ";
}
else
{
this.Label4.Text += "<a href='RepeaterFENYE.aspx?page=" + (curPage + 1).ToString() + "'>下一頁</a> ";
this.Label4.Text += "<a href='RepeaterFENYE.aspx?page=" + pds.PageCount.ToString() + "'>尾頁</a> ";
//this.Label4.Text += "<a href='wjProduct-" + (curPage + 1).ToString() + "-" + Menu_ID + ".html'>下一頁</a> ";
//this.Label4.Text += "<a href='wjProduct-" + pds.PageCount.ToString() + "-" + Menu_ID + ".html'>尾頁</a> ";
}
string HtmlSelectString = "<select onchange=\"javascript:window.location=this.value\">";
for (int i = 1; i <= pds.PageCount; i++)
{
if (i == curPage)
{
//HtmlSelectString += "<option value=wjProduct-" + i + "-" + Menu_ID + ".html selected>第" + i + "頁</option>";
HtmlSelectString += "<option value='RepeaterFENYE.aspx?page=" + i.ToString() +"' selected>第" + i + "頁</option>";
}
else
{
//HtmlSelectString += "<option value=wjProduct-" + i + "-" + Menu_ID + ".html>第" + i + "頁</option>";
HtmlSelectString += "<option value='RepeaterFENYE.aspx?page=" + i.ToString() + "'>第" + i + "頁</option>";
}
}
HtmlSelectString += "</select>";
this.Label4.Text += "<a>" + HtmlSelectString + "</a>";
}
else
{
Label4.Text = "沒有數(shù)據(jù)!";
}
}
}
注://注釋部分為url rewrite的效果。。。li返回的值為SQL查詢后所得到表中所有的記錄。。。
您可能感興趣的文章:
- 在ASP.NET 2.0中操作數(shù)據(jù)之四十一:DataList和Repeater數(shù)據(jù)分頁
- .NET實(shí)現(xiàn)Repeater控件+AspNetPager控件分頁
- asp.net Repeater分頁實(shí)例(PageDataSource的使用)
- asp.net中使用repeater和PageDataSource搭配實(shí)現(xiàn)分頁代碼
- asp.net中讓Repeater和GridView支持DataPager分頁
- asp.net下Repeater使用 AspNetPager分頁控件
- asp.net Repeater之非常好的數(shù)據(jù)分頁
- ASP.NET程序中用Repeater實(shí)現(xiàn)分頁
- .NET中的repeater簡介及分頁效果
相關(guān)文章
.net開發(fā)微信公眾平臺(tái)實(shí)例教程
這篇文章主要介紹了.net開發(fā)微信公眾平臺(tái)的方法,對(duì)微信公眾平臺(tái)開發(fā)的原理與相應(yīng)的.net實(shí)現(xiàn)方法都做了較為詳細(xì)的講述,非常實(shí)用,需要的朋友可以參考下2014-10-10ASP.NET Core3.X 終端中間件轉(zhuǎn)換為端點(diǎn)路由運(yùn)行詳解
這篇文章主要介紹了ASP.NET Core3.X 終端中間件轉(zhuǎn)換為端點(diǎn)路由運(yùn)行,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-12-12.NET Core利用skiasharp文字頭像生成方法教程(基于docker發(fā)布)
這篇文章主要給大家介紹了關(guān)于.NET Core利用skiasharp文字頭像生成(基于docker發(fā)布)的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧。2018-03-03asp.net fileupload控件上傳圖片并預(yù)覽圖片
這篇文章主要介紹了asp.net fileupload控件上傳圖片后并進(jìn)行預(yù)覽圖片的功能,需要的朋友可以參考下2015-11-11ASP.NET Core Middleware的實(shí)現(xiàn)方法詳解
中間件是組裝到應(yīng)用程序管道中以處理請(qǐng)求和響應(yīng)的軟件。下面這篇文章主要給大家介紹了關(guān)于ASP.NET Core Middleware實(shí)現(xiàn)的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下2019-01-01asp.net+ajaxfileupload.js 實(shí)現(xiàn)文件異步上傳代碼分享
本文給大家分享一段asp.net基于ajaxfileupload.js實(shí)現(xiàn)文件異步上傳的代碼,本人項(xiàng)目中已經(jīng)在使用的代碼,小伙伴們可以直接移植到自己的項(xiàng)目中去。2014-11-11ASP.NET Core Web App應(yīng)用第三方Bootstrap模板的方法教程
這篇文章主要給大家介紹了關(guān)于ASP.NET Core Web App應(yīng)用第三方Bootstrap模板的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起看看吧2018-06-06