自訂分頁UserControl 分享及探討!

來源:互聯網
上載者:User
分頁 ----------Pager.ascx-------------------------------------
<%@ Control Language="c#" AutoEventWireup="false" Codebehind="Test.Pager.ascx.cs" Inherits="Pager" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>
<asp:label id="lbl_PageInfo" runat="server">還未用PagerBind()方法綁定</asp:label> 
<asp:linkbutton id="btn_First" runat="server" Visible="False">首頁</asp:linkbutton> <asp:linkbutton id="btn_Pre" runat="server" Visible="False">前頁</asp:linkbutton> <asp:linkbutton id="btn_Next" runat="server" Visible="False">下頁</asp:linkbutton> <asp:linkbutton id="btn_Last" runat="server" Visible="False">尾頁</asp:linkbutton> <asp:label id="lbl_1" runat="server" Visible="False">轉到</asp:label>
<asp:dropdownlist id="drop_CurPage" runat="server" AutoPostBack="True" Visible="False">
<asp:ListItem Value="0">0</asp:ListItem>
</asp:dropdownlist>
<asp:Label id="lbl_2" runat="server" Visible="False">頁</asp:Label>
----------end--------------------------------------------

----------Pager.ascx.cs-------------------------------------
namespace Test
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

/// <summary>
/// Pager 的摘要說明。
/// </summary>
public class Pager : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.LinkButton btn_First;
protected System.Web.UI.WebControls.LinkButton btn_Pre;
protected System.Web.UI.WebControls.LinkButton btn_Next;
protected System.Web.UI.WebControls.LinkButton btn_Last;
protected System.Web.UI.WebControls.DropDownList drop_CurPage;
protected System.Web.UI.WebControls.Label lbl_1;
protected System.Web.UI.WebControls.Label lbl_2;
protected System.Web.UI.WebControls.Label lbl_PageInfo;

public event EventHandler MyClick;

private void Page_Load(object sender, System.EventArgs e)
{
// 在此處放置使用者代碼以初始化頁面
if (!Page.IsPostBack)
{
RecTotal = 0;
PageSize = 10;
CurPage = 0;
Lang = 0; //中文版
}
}

#region Pager控制項使用協助及參數說明
/*
* 版本:V1.0
本控制項帶有三個自訂屬性和一個方法.具體如下:
屬性:
RecTotal 記錄總數 預設值:0
PageSize 每頁記錄數 預設值:0
CurPage 當前頁 預設值:0
Lang 版本語言 預設值:0 注:0為中文版,1為英文版
方法:
PagerBind 綁定當前自訂控制項,如不綁定,該控制項則不能顯示到頁面上
*/
#endregion

#region Web Form設計器產生的程式碼
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 該調用是 ASP.NET Web Form設計器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 設計器支援所需的方法 - 不要使用代碼編輯器
/// 修改此方法的內容。
/// </summary>
private void InitializeComponent()
{
this.btn_First.Click += new System.EventHandler(this.btn_First_Click);
this.btn_Pre.Click += new System.EventHandler(this.btn_Pre_Click);
this.btn_Next.Click += new System.EventHandler(this.btn_Next_Click);
this.btn_Last.Click += new System.EventHandler(this.btn_Last_Click);
this.drop_CurPage.SelectedIndexChanged += new System.EventHandler(this.drop_CurPage_SelectedIndexChanged);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

#region 共用參數傳遞
public int RecTotal //記錄總數
{
get { return (int)ViewState["RecTotal"]; }
set { ViewState["RecTotal"] = value; }
}

public int PageSize //每頁記錄數
{
get { return (int)ViewState["PageSize"]; }
set { ViewState["PageSize"] = value; }
}

public int CurPage //當前頁
{
get { return (int)ViewState["CurPage"]; }
set { ViewState["CurPage"] = value; }
}

public int Lang //語言選擇
{
get { return (int)ViewState["Lang"]; }
set { ViewState["Lang"] = value; }
}
#endregion

#region 相關方法及事件
public void PagerBind()
{


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.