asp.net repeater手寫分頁執行個體代碼

來源:互聯網
上載者:User

複製代碼 代碼如下: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>當前第<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 = "沒有資料!";
}
}
}
註://注釋部分為url rewrite的效果。。。li返回的值為SQL查詢後所得到表中所有的記錄。。。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.