自定義分頁,用戶控制項

来源:https://www.cnblogs.com/www-mcl-1234/archive/2019/05/13/10858301.html
-Advertisement-
Play Games

//前臺<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 + "&currentPage=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 + "&currentPage=" + 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);
}


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 終於A了這道題啊(坑啊) 教練說:這道題不能用map吧,複雜度不一個O(nlogn)嗎 於是我就一直想不出來,然後看題解代碼,一看就是map... 所以我就在想,那複雜度是不是也不是O(nlogn)呢 教練看了半天,說:好像確實不是誒 原來阻擋我的最大障礙是教練啊!!!(當時只給題面,也不知道時限) ...
  • 一個模塊的 API層(Web層),主要負責如下幾個方面的工作:接收 前端層 提交的數據查詢請求,使用 服務層 提供的 IQueryable 查詢數據源,查詢出需要的數據返回前端。接收 前端層 提交的業務處理請求,調用 服務層 的服務,處理業務需求,並將操作結果返回前端。使用MVC的 Area-Co... ...
  • Ocelot .Net Core開源網關 作者:markjiang7m2 原文地址: 源碼地址:https://gitee.com/Sevenm2/OcelotDemo 今天要給大家介紹的Ocelot是一個基於 .net core的開源WebAPI服務網關項目,它的功能非常強大,包括了路由、請求聚合 ...
  • 本文講述使用window服務創建定時任務 1.如圖,新建項目,windows桌面->windows服務 2.如圖,右鍵,添加安裝程式 3.在下圖安裝程式 serviceInstaller1 上右鍵,修改serviceName和Description 4.如圖,在 serviceProcessInst ...
  • .net core 設置讀取JSON配置文件 appsettings.json Startup.cs 中 類庫中 使用 這種方法可以保證可以修改正在運行的dotnet core 程式,不需要重啟程式 使用Newtonsoft.Json 查詢/修改,以及修改 appsettings.json 文件 R ...
  • 主要是通過修改HOSTS來,解決GitHub載入和下載慢問題。 ...
  • SmartSql = MyBatis + Cache(Memory | Redis) + R/W Splitting +Dynamic Repository + Diagnostics ...... ...
  • //PS 需要引用HtmlAgilityPack.dll 文件,可自行在網上下載 public partial class GrabInterface : Form { public int number = 1; public GrabInterface() { InitializeCompone ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...