可能大家有用得著的地方
Pager
using System;
using System
using System
using System
using System
namespace C_Pager
public class Pager : Control
[Description(
public event EventHandler PageChanged;
private int rectotal =
private int pagesize =
private int curpage =
private int lang =
private int pagetotal =
private string firstpagetext =
private string prevpagetext =
private string nextpagetext =
private string lastpagetext =
protected virtual void temp_Click(object sender
if (PageChanged != null)
PageChanged(this
}
}
Pager控件使用幫助及參數說明#region Pager控件使用幫助及參數說明
/**//*
本控件帶有三個自定義屬性和一個方法
屬性:
RecTotal 記錄總數 默認值:
PageSize 每頁記錄數 默認值:
CurPage 當前頁 默認值:
Lang 版本語言 默認值:
方法:
PagerBind 綁定當前自定義控件
*/
#endregion
控件屬性列表#region 控件屬性列表
[Category(
public int RecTotal
get
set
}
[Category(
public int PageSize
get
set
}
[Category(
public int CurPage
get
set
}
[Category(
public int PageTotal
set
}
[Category(
public int Lang
get
set
}
[Category(
public string FirstPageText //
get
set
}
[Category(
public string PrevPageText
get
set
}
[Category(
public string NextPageText
get
set
}
[Category(
public string LastPageText
get
set
}
#endregion
protected override void CreateChildControls()
ViewState[
ViewState[
ViewState[
ViewState[
Label lbl_PageInfo = new Label(); //
lbl_PageInfo
Controls
LinkButton btn_First = new LinkButton(); //
btn_First
Controls
btn_First
btn_First
Controls
LinkButton btn_Pre = new LinkButton(); //
btn_Pre
Controls
btn_Pre
btn_Pre
Controls
LinkButton btn_Next = new LinkButton(); //
btn_Next
Controls
btn_Next
btn_Next
Controls
LinkButton btn_Last = new LinkButton(); //
btn_Last
Controls
btn_Last
btn_Last
Controls
Label lbl_
lbl_
lbl_
Controls
DropDownList drop_CurPage = new DropDownList(); //
drop_CurPage
Controls
drop_CurPage
drop_CurPage
drop_CurPage
Label lbl_
lbl_
lbl_
Controls
}
protected override void OnPreRender(EventArgs e)
if (!Page
StartVar();
PagerBind();
}
}
protected void StartVar() //初始各參數.希望只執行一次
ViewState[
ViewState[
ViewState[
ViewState[
ViewState[
}
相關方法及事件#region 相關方法及事件
public void PagerBind()
ViewState[
if ((int)ViewState[
((Label)Controls[
}
else
((Label)Controls[
((Label)Controls[
((Label)Controls[
}
((DropDownList)Controls[
int i=
do
((DropDownList)Controls[
i++;
}
while (i<(int)ViewState[
((DropDownList)Controls[
((LinkButton)Controls[
((LinkButton)Controls[
((LinkButton)Controls[
((LinkButton)Controls[
((Label)Controls[
((Label)Controls[
((DropDownList)Controls[
((LinkButton)Controls[
((LinkButton)Controls[
((LinkButton)Controls[
((LinkButton)Controls[
if ((int)ViewState[
((LinkButton)Controls[
((LinkButton)Controls[
((LinkButton)Controls[
((LinkButton)Controls[
}
if ((int)ViewState[
((LinkButton)Controls[
((LinkButton)Controls[
((LinkButton)Controls[
((LinkButton)Controls[
}
if (( (int)ViewState[
((LinkButton)Controls[
((LinkButton)Controls[
((LinkButton)Controls[
((LinkButton)Controls[
}
CurPage = (int)ViewState[
RecTotal = (int)ViewState[
PageSize = (int)ViewState[
CurPage = (int)ViewState[
Lang = (int)ViewState[
PageTotal = (int)ViewState[
}
private void drop_CurPage_SelectedIndexChanged(object sender
ViewState[
PagerBind();
if (PageChanged != null)
temp_Click(this
}
private void btn_First_Click(object sender
ViewState[
PagerBind();
if (PageChanged != null)
temp_Click(this
}
private void btn_Pre_Click(object sender
ViewState[
PagerBind();
if (PageChanged != null)
temp_Click(this
}
private void btn_Next_Click(object sender
ViewState[
PagerBind();
if (PageChanged != null)
temp_Click(this
}
private void btn_Last_Click(object sender
ViewState[
PagerBind();
if (PageChanged != null)
temp_Click(this
}
#endregion
}
}
WebForm
具體效果展示頁面
<%@ Page language=
<%@ Register TagPrefix=
<!DOCTYPE HTML PUBLIC
<HTML>
<HEAD>
<title>WebForm
<meta content=
<meta content=
<meta content=
<meta content=
</HEAD>
<body MS_POSITIONING=
<form id=
<FONT face=
<cc
<asp:DataGrid id=
Width=
</body>
</HTML>
WebForm
using System;
using System
using System
using System
using System
using System
using System
using System
using System
using System
using System
using System
namespace MyWebControll
/**//// <summary>
/// WebForm
/// </summary>
public class WebForm
protected C_Pager
protected OleDbConnection conn;
protected System
protected OleDbCommand cmd;
private void Page_Load(object sender
// 在此處放置用戶代碼以初始化頁面
conn=new OleDbConnection(
if(!Page
DataBind(
}
}
Web 窗體設計器生成的代碼#region Web 窗體設計器生成的代碼
override protected void OnInit(EventArgs e)
//
// CODEGEN: 該調用是 ASP
//
InitializeComponent();
base
}
/**//// <summary>
/// 設計器支持所需的方法
/// 此方法的內容
/// </summary>
private void InitializeComponent()
this
this
}
#endregion
private void DataBind(int CurPage) //數據綁定方法
cmd=new OleDbCommand(
OleDbDataAdapter adapter=new OleDbDataAdapter(cmd);
DataSet ds=new DataSet();
adapter
DataGrid
DataGrid
cmd=new OleDbCommand(
conn
Pager
Pager
conn
}
private void Change(object sender
DataBind(Pager
}
}
}
From:http://tw.wingwit.com/Article/program/net/201311/11748.html