296 lines
7.3 KiB
C#
296 lines
7.3 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Web;
|
|||
|
using System.Web.UI;
|
|||
|
using System.Web.UI.WebControls;
|
|||
|
|
|||
|
public partial class public_Pager : System.Web.UI.UserControl
|
|||
|
{
|
|||
|
|
|||
|
/**/
|
|||
|
/// <summary>
|
|||
|
/// 申明委托
|
|||
|
/// </summary>
|
|||
|
/// <param name="e"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public delegate int EventPagingHandler(EventPagingArg e);
|
|||
|
/**/
|
|||
|
/// <summary>
|
|||
|
/// 分页控件呈现
|
|||
|
/// </summary>
|
|||
|
protected void Page_Load(object sender, EventArgs e)
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
public event EventPagingHandler EventPaging;
|
|||
|
/**/
|
|||
|
/// <summary>
|
|||
|
/// 每页显示记录数
|
|||
|
/// </summary>
|
|||
|
private int _pageSize = 100;
|
|||
|
/**/
|
|||
|
/// <summary>
|
|||
|
/// 每页显示记录数
|
|||
|
/// </summary>
|
|||
|
public int PageSize
|
|||
|
{
|
|||
|
get { return _pageSize; }
|
|||
|
set
|
|||
|
{
|
|||
|
_pageSize = value;
|
|||
|
GetPageCount();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private int _nMax = 0;
|
|||
|
/**/
|
|||
|
/// <summary>
|
|||
|
/// 总记录数
|
|||
|
/// </summary>
|
|||
|
public int NMax
|
|||
|
{
|
|||
|
get { return _nMax; }
|
|||
|
set
|
|||
|
{
|
|||
|
_nMax = value;
|
|||
|
GetPageCount();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private int _pageCount = 0;
|
|||
|
/**/
|
|||
|
/// <summary>
|
|||
|
/// 页数=总记录数/每页显示记录数
|
|||
|
/// </summary>
|
|||
|
public int PageCount
|
|||
|
{
|
|||
|
get { return _pageCount; }
|
|||
|
set { _pageCount = value; }
|
|||
|
}
|
|||
|
|
|||
|
private int _pageCurrent = 0;
|
|||
|
/**/
|
|||
|
/// <summary>
|
|||
|
/// 当前页号
|
|||
|
/// </summary>
|
|||
|
public int PageCurrent
|
|||
|
{
|
|||
|
get { return _pageCurrent; }
|
|||
|
set { _pageCurrent = value; }
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 设置页面大小
|
|||
|
/// </summary>
|
|||
|
private void GetPageCount()
|
|||
|
{
|
|||
|
if (this.NMax > 0)
|
|||
|
{
|
|||
|
this.PageCount = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(this.NMax) / Convert.ToDouble(this.PageSize)));
|
|||
|
// lblPageCount.Text = " / " + PageCount.ToString();
|
|||
|
lblcurentpage.Text = PageCurrent.ToString() + " / " + PageCount.ToString();
|
|||
|
//lblPageCount1.Text = "每页 "+PageSize .ToString ()+" 条,共 "+PageCount.ToString()+" 页";
|
|||
|
// lblPageCount1.Text = "Page no: " + PageSize.ToString() + ",Total:" + PageCount.ToString() + " pages";
|
|||
|
// lblPageCount1.Text = PageSize.ToString() + "/" + PageCount.ToString() ;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
this.PageCount = 0;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/**/
|
|||
|
/// <summary>
|
|||
|
/// 翻页控件数据绑定的方法 关键是这步,都是调用这里
|
|||
|
/// </summary>
|
|||
|
public void Bind()
|
|||
|
{
|
|||
|
if (this.EventPaging != null)
|
|||
|
{
|
|||
|
this.NMax = this.EventPaging(new EventPagingArg(this.PageCurrent));
|
|||
|
}
|
|||
|
|
|||
|
if (this.PageCurrent > this.PageCount)
|
|||
|
{
|
|||
|
this.PageCurrent = this.PageCount;
|
|||
|
}
|
|||
|
if (this.PageCount == 1)
|
|||
|
{
|
|||
|
this.PageCurrent = 1;
|
|||
|
}
|
|||
|
lblcurentpage.Text = PageCurrent.ToString() + " / " + PageCount.ToString();
|
|||
|
lblRecordCount.Text = "共" + NMax.ToString() + "条";
|
|||
|
// lblRecordCount.Text = "Total: " + NMax.ToString() + " records";
|
|||
|
|
|||
|
|
|||
|
btnPrev.Enabled = true;
|
|||
|
btnFirst.Enabled = true;
|
|||
|
btnLast.Enabled = true;
|
|||
|
btnNext.Enabled = true;
|
|||
|
|
|||
|
if (this.PageCurrent == 1)
|
|||
|
{
|
|||
|
this.btnPrev.Enabled = false;
|
|||
|
this.btnFirst.Enabled = false;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
if (this.PageCurrent == this.PageCount)
|
|||
|
{
|
|||
|
this.btnLast.Enabled = false;
|
|||
|
this.btnNext.Enabled = false;
|
|||
|
}
|
|||
|
|
|||
|
if (this.NMax == 0)
|
|||
|
{
|
|||
|
btnNext.Enabled = false;
|
|||
|
btnLast.Enabled = false;
|
|||
|
btnFirst.Enabled = false;
|
|||
|
btnPrev.Enabled = false;
|
|||
|
}
|
|||
|
cmbPagecount.Items.Clear();
|
|||
|
for (int i = 1; i <= PageCount; i++)
|
|||
|
{
|
|||
|
cmbPagecount.Items.Add(i.ToString());
|
|||
|
//if(i== PageCurrent - 1){
|
|||
|
// cmbPagecount.SelectedItem = cmbPagecount.Items[i - 1];
|
|||
|
//}
|
|||
|
}
|
|||
|
this.cmbPagecount.SelectedIndexChanged -= new System.EventHandler(this.cmbPagecount_SelectedIndexChanged);
|
|||
|
cmbPagecount.SelectedIndex = PageCurrent - 1;
|
|||
|
this.cmbPagecount.SelectedIndexChanged += new System.EventHandler(this.cmbPagecount_SelectedIndexChanged);
|
|||
|
|
|||
|
|
|||
|
comPagesize.Items.Clear();
|
|||
|
for (int i = 100; i <= 900; i += 100)
|
|||
|
{
|
|||
|
comPagesize.Items.Add(i.ToString());
|
|||
|
|
|||
|
}
|
|||
|
/*
|
|||
|
for (int i = 50; i <= 500; i+=50)
|
|||
|
{
|
|||
|
comPagesize.Items.Add(i.ToString());
|
|||
|
|
|||
|
}
|
|||
|
*/
|
|||
|
for (int i = 1000; i <= 5000; i += 1000)
|
|||
|
{
|
|||
|
comPagesize.Items.Add(i.ToString());
|
|||
|
}
|
|||
|
this.comPagesize.SelectedIndexChanged -= new System.EventHandler(this.comPagesize_SelectedIndexChanged);
|
|||
|
// comPagesize.SelectedIndex = this._pageSize / 100 -1;
|
|||
|
// comPagesize.SelectedIndex = this._pageSize / 50 - 1 ;
|
|||
|
comPagesize.SelectedIndex = _pageSize <= 1000 ? this._pageSize / 100 - 1 : 10 + _pageSize / 1000 - 2;
|
|||
|
this.comPagesize.SelectedIndexChanged += new System.EventHandler(this.comPagesize_SelectedIndexChanged);
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 首页
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
public void btnFirst_Click(object sender, ImageClickEventArgs e)
|
|||
|
{
|
|||
|
PageCurrent = 1;
|
|||
|
this.Bind();
|
|||
|
}
|
|||
|
//上一页
|
|||
|
/// <summary>
|
|||
|
///
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
public void btnPrev_Click(object sender, ImageClickEventArgs e)
|
|||
|
{
|
|||
|
PageCurrent -= 1;
|
|||
|
if (PageCurrent <= 0)
|
|||
|
{
|
|||
|
PageCurrent = 1;
|
|||
|
}
|
|||
|
this.Bind();
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 下一页
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
public void btnNext_Click(object sender, ImageClickEventArgs e)
|
|||
|
{
|
|||
|
this.PageCurrent += 1;
|
|||
|
if (PageCurrent > PageCount)
|
|||
|
{
|
|||
|
PageCurrent = PageCount;
|
|||
|
}
|
|||
|
this.Bind();
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 最后页
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
public void btnLast_Click(object sender, ImageClickEventArgs e)
|
|||
|
{
|
|||
|
PageCurrent = PageCount;
|
|||
|
this.Bind();
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 转到新页
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
public void btnGo_Click(object sender, ImageClickEventArgs e)
|
|||
|
{
|
|||
|
if (Int32.TryParse(cmbPagecount.SelectedItem.ToString(), out _pageCurrent))
|
|||
|
{
|
|||
|
this.Bind();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public void cmbPagecount_SelectedIndexChanged(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (Int32.TryParse(cmbPagecount.SelectedItem.ToString(), out _pageCurrent))
|
|||
|
{
|
|||
|
this.Bind();
|
|||
|
}
|
|||
|
}
|
|||
|
public void comPagesize_SelectedIndexChanged(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (Int32.TryParse(comPagesize.SelectedItem.ToString(), out _pageSize))
|
|||
|
{
|
|||
|
GetPageCount();
|
|||
|
this.Bind();
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
} /**/
|
|||
|
/// <summary>
|
|||
|
/// 自定义事件数据基类
|
|||
|
/// </summary>
|
|||
|
public class EventPagingArg : EventArgs
|
|||
|
{
|
|||
|
private int _intPageIndex;
|
|||
|
public EventPagingArg(int PageIndex)
|
|||
|
{
|
|||
|
_intPageIndex = PageIndex;
|
|||
|
}
|
|||
|
}
|