1:首先写一个分页控件
如图:
代码:
public partial class ControlPage_QueryData : UserControl
{
public DataTable table = new DataTable();
public ControlPage_QueryData()
{
InitializeComponent();
}
public ControlPage_QueryData(DataTable dt)
{
InitializeComponent();
table = dt;
}
#region 分页字段和属性
private int pageIndex = 1;
/// <summary>
/// 当前页面
/// </summary>
public int PageIndex
{
get { return pageIndex; }
set { pageIndex = value; }
}
private int pageSize = 10;
/// <summary>
/// 每页记录数
/// </summary>
public int PageSize
{
get { return pageSize; }
set { pageSize = value; }
}
private int recordCount = 0;
/// <summary>
/// 总记录数
/// </summary>
public int RecordCount
{
get { return recordCount; }
set { recordCount = value; }
}
private int pageCount = 0;
/// <summary>
/// 总页数
/// </summary>
public int PageCount
{
get
{
if (pageSize != 0)
{
pageCount = GetPageCount();
}
return pageCount;
}
}
/// <summary>
/// 计算总页数
/// </summary>
/// <returns></returns>
private int GetPageCount()
{
if (PageSize == 0)
{
return 0;
}
int pageCount = RecordCount / PageSize;
if (RecordCount % PageSize == 0)
{
pageCount = RecordCount / PageSize;
}
else
{
pageCount = RecordCount / PageSize + 1;