明輝手游網(wǎng)中心:是一個免費提供流行視頻軟件教程、在線學(xué)習(xí)分享的學(xué)習(xí)平臺!

WebForm2WebForm2

[摘要]----------Pager.ascx-------------------------------------<%@ Control Language="c#" AutoEventWireup="false" Codebehind="Te...
----------Pager.ascx-------------------------------------<%@ Control Language="c#" AutoEventWireup="false" Codebehind="Test.Pager.ascx.cs" Inherits="Pager" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %>還未用PagerBind()方法綁定 首頁 前頁 下頁 尾頁 轉(zhuǎn)到 0----------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; /// /// Pager 的摘要說明。 /// 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控件使用幫助及參數(shù)說明 /* * 版本:V1.0 本控件帶有三個自定義屬性和一個方法.具體如下: 屬性: RecTotal 記錄總數(shù) 默認(rèn)值:0 PageSize 每頁記錄數(shù) 默認(rèn)值:0 CurPage 當(dāng)前頁 默認(rèn)值:0 Lang 版本語言 默認(rèn)值:0 注:0為中文版,1為英文版 方法: PagerBind 綁定當(dāng)前自定義控件,如不綁定,該控件則不能顯示到頁面上 */ #endregion #region Web 窗體設(shè)計器生成的代碼 override protected void OnInit(EventArgs e) { // // CODEGEN: 該調(diào)用是 ASP.NET Web 窗體設(shè)計器所必需的。 // InitializeComponent(); base.OnInit(e); } /// /// 設(shè)計器支持所需的方法 - 不要使用代碼編輯器 /// 修改此方法的內(nèi)容。 /// 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 共用參數(shù)傳遞 public int RecTotal //記錄總數(shù) { get { return (int)ViewState["RecTotal"]; } set { ViewState["RecTotal"] = value; } } public int PageSize //每頁記錄數(shù) { get { return (int)ViewState["PageSize"]; } set { ViewState["PageSize"] = value; } } public int CurPage //當(dāng)前頁 { get { return (int)ViewState["CurPage"]; } set { ViewState["CurPage"] = value; } } public int Lang //語言選擇 { get { return (int)ViewState["Lang"]; } set { ViewState["Lang"] = value; } } #endregion #region 相關(guān)方法及事件 public void PagerBind() { ViewState["PageTotal"]=((int)ViewState["RecTotal"]%(int)ViewState["PageSize"]>0) ? (int)ViewState["RecTotal"]/(int)ViewState["PageSize"]+1 : (int)ViewState["RecTotal"]/(int)ViewState["PageSize"]; //頁總數(shù) if ((int)ViewState["Lang"]==0) { lbl_PageInfo.Text="共"+ViewState["RecTotal"].ToString()+"條信息 "+ViewState["PageSize"].ToString()+"條/頁 當(dāng)前"+((int)ViewState["CurPage"]+1).ToString()+"/"+ViewState["PageTotal"].ToString()+"頁"; } else { lbl_PageInfo.Text="Total"+ViewState["RecTotal"].ToString()+"Info "+ViewState["PageSize"].ToString()+"/Page Current"+((int)ViewState["CurPage"]+1).ToString()+"/"+ViewState["PageTotal"].ToString()+"Page"; lbl_1.Text = "To"; lbl_2.Text = "Page"; btn_First.Text = "First"; btn_Pre.Text = "Forward"; btn_Next.Text = "Next"; btn_Last.Text = "Last"; } drop_CurPage.Items.Clear(); for (int i=0;i<(int)viewstate["pagetotal"];i++) {="" drop_curpage.items.add(convert.tostring(i+1));="" }="" drop_curpage.selectedindex="drop_CurPage.Items.IndexOf(drop_CurPage.Items.FindByValue(Convert.ToString((int)ViewState[" curpage"]+1)));"="" btn_first.visible="true;" btn_pre.visible="true;" btn_next.visible="true;" btn_last.visible="true;" lbl_1.visible="true;" lbl_2.visible="true;" drop_curpage.visible="true;" btn_first.enabled="true;" btn_pre.enabled="true;" btn_next.enabled="true;" btn_last.enabled="true;" if="" ((int)viewstate["curpage"]="=0)" {="" btn_first.enabled="false;" btn_pre.enabled="false;" btn_next.enabled="true;" btn_last.enabled="true;" }="" if="" ((int)viewstate["curpage"]="=(" (int)viewstate["pagetotal"]-1)="" )="" {="" btn_first.enabled="true;" btn_pre.enabled="true;" btn_next.enabled="false;" btn_last.enabled="false;" }="" if="" ((="" (int)viewstate["pagetotal"]-1)="=" 0="" )="" {="" btn_first.enabled="false;" btn_pre.enabled="false;" btn_next.enabled="false;" btn_last.enabled="false;" }="" }="" private="" void="" drop_curpage_selectedindexchanged(object="" sender,="" system.eventargs="" e)="" {="" viewstate["curpage"]="drop_CurPage.SelectedIndex;" pagerbind();="" if="" (myclick="" !="null)" myclick(this,="" eventargs.empty);="" }="" private="" void="" btn_first_click(object="" sender,="" system.eventargs="" e)="" {="" viewstate["curpage"]="0;" pagerbind();="" if="" (myclick="" !="null)" myclick(this,="" eventargs.empty);="" }="" private="" void="" btn_pre_click(object="" sender,="" system.eventargs="" e)="" {="" viewstate["curpage"]="(int)ViewState[" curpage"]-1;"="" pagerbind();="" if="" (myclick="" !="null)" myclick(this,="" eventargs.empty);="" }="" private="" void="" btn_next_click(object="" sender,="" system.eventargs="" e)="" {="" viewstate["curpage"]="(int)ViewState[" curpage"]+1;"="" pagerbind();="" if="" (myclick="" !="null)" myclick(this,="" eventargs.empty);="" }="" private="" void="" btn_last_click(object="" sender,="" system.eventargs="" e)="" {="" viewstate["curpage"]="(int)ViewState[" pagetotal"]-1;"="" pagerbind();="" if="" (myclick="" !="null)" myclick(this,="" eventargs.empty);="" }="" #endregion="" }}-----------------------------------------------------------------------------------------調(diào)用頁面webform1.aspx--------------------------------------------<%@="" page="" language="c#" codebehind="WebForm1.aspx.cs" autoeventwireup="false" inherits="Test.WebForm1" %><%@="" register="" tagprefix="uc1" tagname="Pager" src="Pager.ascx" %><doctype="" html="" public="" "-//w3c//dtd="" html="" 4.0="" transitional//en"=""> WebForm2 -----------------------------------------------------------------------------------------------調(diào)用頁面WebForm1.aspx.cs--------------------------------------------using System;using System.Collections;using System.ComponentModel;using System.Data;using System.Drawing;using System.Web;using System.Web.SessionState;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.HtmlControls;namespace Test{ /// /// WebForm2 的摘要說明。 /// public class WebForm1 : System.Web.UI.Page { protected System.Web.UI.WebControls.DataGrid DataGrid1; protected Test.Pager Pager1; private void Page_Load(object sender, System.EventArgs e) { // 在此處放置用戶代碼以初始化頁面 DataGrid1Bind(0); } #region Web 窗體設(shè)計器生成的代碼 override protected void OnInit(EventArgs e) { // // CODEGEN: 該調(diào)用是 ASP.NET Web 窗體設(shè)計器所必需的。 // InitializeComponent(); base.OnInit(e); } /// /// 設(shè)計器支持所需的方法 - 不要使用代碼編輯器修改 /// 此方法的內(nèi)容。 /// private void InitializeComponent() { this.Load += new System.EventHandler(this.Page_Load); } #endregion private void DataGrid1Bind(int Page) { DataGrid1.DataSource = myDataSource; //此處請自行綁定當(dāng)前頁數(shù)據(jù)集的數(shù)據(jù)源 DataGrid1.DataBind(); Pager1.RecTotal = MyTotal; //此處請自行綁定數(shù)據(jù)集總記錄數(shù) Pager1.PageSize = 10; Pager1.CurPage = Page; Pager1.Lang = 0; //0為中文版,1為英文版 Pager1.PagerBind(); } public void GetPage(Object sender, EventArgs e) { DataGrid1Bind(Pager1.CurPage); } }}


標(biāo)簽:WebForm2WebForm2 

相關(guān)文章