日期:2013-10-26  浏览次数:21023 次

----------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 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
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[&quo