//前臺<script type="text/javascript"> function PageChange() { var path = "<%=PathUrl%>"; if (path != "" && path != null) { location.href = path + "&curr ...
//前臺
<script type="text/javascript">
function PageChange() {
var path = "<%=PathUrl%>";
if (path != "" && path != null) {
location.href = path + "¤tPage=1" + "&pageSize=" + Number($(".Selectchange option:selected").val());
}
else {
location.href = "?currentPage=1" + "&pageSize=" + Number($(".Selectchange option:selected").val());
}
}
function TurnPage(type) {
var currentPage = "<%=currentPage%>" == null ? 1 : Number("<%=currentPage%>");
var maxPage = "<%=maxPage%>";
switch (type) {
case "f":
if (currentPage == 1) {
return;
}
else {
currentPage = 1;
}
break;
case "p":
if (currentPage <= 1) {
return;
}
else {
currentPage = currentPage - 1;
}
break;
case "n":
if (currentPage >= maxPage) {
return;
}
else {
currentPage = currentPage + 1;
}
break;
case "e":
if (currentPage == maxPage) return;
currentPage = maxPage;
break;
default:
break;
}
if (!isNaN(currentPage) && currentPage > 0) {
var path = "<%=PathUrl%>";
if (path != "" && path != null) {
location.href = path + "¤tPage=" + currentPage + "&pageSize=" + Number($(".Selectchange option:selected").val());
}
else {
location.href = "?currentPage=" + currentPage + "&pageSize=" + Number($(".Selectchange option:selected").val());
}
}
}
</script>
<style type="text/css">
.container {
height: 24px;
width: 98%;
}
.first {
float: left;
left: 0px;
font-size: 15px;
line-height: 24px;
}
.pagination {
width:400px;
margin: auto;
height: 24px;
}
.pagination li {
float: left;
margin-right: 5px;
border: #e2e2e2 1px solid;
}
.pagination > li > span {
position: relative;
float: left;
padding: 2px 12px;
margin-left: -1px;
color: #428bca;
text-decoration: none;
background-color: #fff;
border: 1px solid #ddd;
}
.Selectchange {
line-height: 24px;
font-size: 15px;
}
.end {
border: 0px !important;
line-height: 24px;
}
</style>
<div class="container">
<span class="first">共<%=total %>條數據</span>
<ul id="PagerID" class="pagination">
<li>
<input type="button" onclick="TurnPage('f')" id="HomePage" runat="server" name="name" value="首頁"></li>
<li>
<input type="button" onclick="TurnPage('p')" id="OnPage" runat="server" name="name" value="上頁" /></li>
<li>
<span>頁:<asp:Label ID="lbl_CurrentPage" runat="server">0</asp:Label>/<asp:Label ID="lbl_MaxPage" runat="server">0</asp:Label></span>
</li>
<li>
<input type="button" onclick="TurnPage('n')" id="NextPage" runat="server" name="name" value="下頁" /></li>
<li>
<input type="button" onclick="TurnPage('e')" id="BackPage" runat="server" name="name" value="末頁" /></li>
<li class="end">
<span class="end">每頁顯示:<asp:DropDownList ID="Selectchange" class="Selectchange" onchange="PageChange()" runat="server">
<asp:ListItem Value="10">10</asp:ListItem>
<asp:ListItem Value="20">20</asp:ListItem>
<asp:ListItem Value="30">30</asp:ListItem>
</asp:DropDownList></span></li>
</ul>
</div>
//後臺
public partial class Pageing : System.Web.UI.UserControl
{
/// <summary>
/// 當前頁碼
/// </summary>
public int currentPage;
/// <summary>
/// 每頁顯示數量
/// </summary>
public int pageSize;
/// <summary>
/// 共計多少頁
/// </summary>
public int maxPage;
/// <summary>
/// 總數據數量
/// </summary>
public int total;
/// <summary>
/// 頁面路徑(備註:有外加查詢條件時,則賦值,沒有外加查詢條件時顯示為空)
/// </summary>
public string PathUrl;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
#region 此處為前臺分頁四個按鈕的控制項樣式(H-UI 框架按鈕樣式)
if (currentPage == 1)
{
this.HomePage.Attributes.Add("class", "btn size-MINI radius disabled");
this.OnPage.Attributes.Add("class", "btn size-MINI radius disabled");
}
else
{
this.HomePage.Attributes.Add("class", "btn btn-primary size-MINI radius");
this.OnPage.Attributes.Add("class", "btn btn-primary size-MINI radius");
}
if (currentPage == maxPage || maxPage == 0)
{
this.NextPage.Attributes.Add("class", "btn size-MINI radius disabled");
this.BackPage.Attributes.Add("class", "btn size-MINI radius disabled");
}
else
{
this.NextPage.Attributes.Add("class", "btn btn-primary size-MINI radius");
this.BackPage.Attributes.Add("class", "btn btn-primary size-MINI radius");
}
#endregion
}
}
/// <summary>
/// 分頁方法
/// </summary>
/// <typeparam name="T">實體</typeparam>
/// <param name="list_Model">分頁數據源</param>
/// <param name="rpt_DateShow">分頁綁定控制項</param>
/// <param name="total">總記錄數</param>
/// <param name="currentPageNext">當前頁</param>
/// <param name="pageSize">每頁顯示數據</param>
/// <param name="Url">界面傳遞參數</param>
public void O_Pageing<T>(List<T> list_Model, Repeater rpt_DateShow, int _total, int _currentPage, int _pageSize, string _PathUrl)
{
currentPage = _currentPage;
PathUrl = _PathUrl;
total = _total;
pageSize = _pageSize;
//int index = Request.Url.LocalPath.LastIndexOf('/');
//string path = Request.Url.LocalPath.Substring(index);//獲取當前界面路徑
this.Selectchange.SelectedValue = pageSize.ToString();
maxPage = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(total) / Convert.ToDouble(pageSize)));
lbl_CurrentPage.Text = currentPage + "";
lbl_MaxPage.Text = maxPage + "";
rpt_DateShow.DataSource = list_Model;
rpt_DateShow.DataBind();
}
/// <summary>
/// 分頁方法
/// </summary>
/// <param name="dt"></param>
/// <param name="rpt_DateShow"></param>
/// <param name="_total"></param>
/// <param name="_currentPage"></param>
/// <param name="pageSize"></param>
/// <param name="Url"></param>
public void O_Pageing(DataTable dt, Repeater rpt_DateShow, int _total, int _currentPage, int _pageSize, string _PathUrl)
{
currentPage = _currentPage;
PathUrl = _PathUrl;
total = _total;
pageSize = _pageSize;
//int index = Request.Url.LocalPath.LastIndexOf('/');
//string path = Request.Url.LocalPath.Substring(index);//獲取當前界面路徑
this.Selectchange.SelectedValue = pageSize.ToString();
maxPage = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(total) / Convert.ToDouble(pageSize)));
lbl_CurrentPage.Text = currentPage + "";
lbl_MaxPage.Text = maxPage + "";
rpt_DateShow.DataSource = dt;
rpt_DateShow.DataBind();
}
}
//後端,僅供參考( CRequest.GetInt為自定義封裝類,用於獲取傳遞參數)
public int currentPage = CRequest.GetInt("currentPage", 1);//當前頁碼
public int pageSize = CRequest.GetInt("pageSize", 10);//每頁顯示數量
public int total = 0;//分頁總數據
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataPage();
}
}
public void DataPage()
{
string PathUrl = "ModuleList.aspx?modulename=" + name;//此處為當前頁面後臺傳遞的參數
//list_Modules 為數據源, rpt_ModelShow 為前臺綁定數據控制項
this.Pageing.O_Pageing<Modules>(list_Modules, rpt_ModelShow, total, currentPage, pageSize, PathUrl);
}