#region 显示分页数据信息列表
/// <summary>
/// 显示分页数据信息列表
/// </summary>
/// <param name="intPage">页号</param>
/// <returns> </returns>
private DataTable CreateTaskTable(int intPage, string sql)
{
int intPageCount = 1;
int intRecordCount = 1;
DataTable dtTasks;
try
{
//取得任务集合,并得到当前页号、页数、记录数
//得到用户所有类型的任务
dtTasks =GetTasksAlready(this.intPageSize, ref intPage, out intPageCount, out intRecordCount, sql);
#region 设置翻页信息
//将取得的页号记录在ViewState中
ViewState["Page"] = intPage;
//将取得的页数记录在ViewState中
ViewState["PageCount"] = intPageCount;
lblPageMsg.Text = "共<font color='#0099CC'>" + intPageCount.ToString()
+ "</font>页 每页<font color='#0099CC'>" + intPageSize.ToString()
+ "</font>条 总共<font color='#0099CC'>" + intRecordCount.ToString()
+ "</font>条 当前是第<font color='#0099CC'>"
+ intPage.ToString() + "</font>页 ";
this.tbPage.Visible = true;
txtPage.Text = intPage.ToString();
if (intPage >= intPageCount)
{
lbtnLast.Enabled = false;
lbtnNext.Enabled = false;
}
else
{
lbtnLast.Enabled = true;
lbtnNext.Enabled = true;
}
if (intPage <= 1)
{
lbtnFirst.Enabled = false;
lbtnPrev.Enabled = false;
}
else
{
lbtnFirst.Enabled = true;
lbtnPrev.Enabled = true;
}
if (intRecordCount > 0)
{
txtPage.Enabled = true;
}
else
{
txtPage.Enabled = false;
}
#endregion
return dtTasks;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取分页数据信息列表
/// <summary>
/// 获取分页数据信息列表
/// </summary>
/// <param name="intPageSize">显示信息数目条数</param>
/// <param name="intPage">第几页</param>
/// <param name="intPageCount">页数总和</param>
/// <param name="intRecordCount">总记录条数</param>
/// <param name="sql">查询sql语句</param>
/// <returns></returns>
public static DataTable GetTasksAlready(int intPageSize, ref int intPage, out int intPageCount, out int intRecordCount, string sql)
{
DataTable dt = new DataTable();
dt = new MSSqlDataAccessYZ().ExecuteDataTable(CommandType.Text, sql, null, null);
DataTable newTasks = dt.Clone();
intRecordCount = dt.Rows.Count;
if (intRecordCount % intPageSize == 0)
{
intPageCount = intRecordCount / intPageSize;
}
else
{
intPageCount = intRecordCount / intPageSize + 1;
}
if (intPageCount <= 0)
{
intPageCount = 1;
}
if (intPage < 1)
{
intPage = 1;
}
if (intPage >= intPageCount)
{
intPage = intPageCount;
}
int intStartPosition = intPageSize * (intPage - 1);
int intEndPosition = intStartPosition + intPageSize;
if (intEndPosition > intRecordCount)
{
intEndPosition = intRecordCount;
}
if (dt.Rows.Count != 0)
{
//遍历每一个任务,取得相应的信息
for (int i = intStartPosition; i < intEndPosition; i++)
{
DataRow drNewRow = newTasks.NewRow();
drNewRow.ItemArray = dt.Rows[i].ItemArray;//这是加入的是第一行
newTasks.Rows.Add(drNewRow);
}
}
return newTasks;
}
#endregion
前端代码:
<table id="tbPage" cellspacing="0" cellpadding="0" align="center" border="0" runat="server">
<tr style="font-size: 9pt" height="22">
<td width="3%">
</td>
<td nowrap width="38%">
<asp:Label ID="lblPageMsg" runat="server"></asp:Label>
</td>
<td nowrap width="8%">
<asp:LinkButton ID="lbtnFirst" runat="server" OnClick="lbtnFirst_Click">第一页</asp:LinkButton>
</td>
<td nowrap width="8%">
<asp:LinkButton ID="lbtnPrev" runat="server" OnClick="lbtnPrev_Click">上一页</asp:LinkButton>
</td>
<td nowrap width="8%">
<asp:LinkButton ID="lbtnNext" runat="server" οnclick="lbtnNext_Click">下一页</asp:LinkButton>
</td>
<td nowrap width="8%">
<asp:LinkButton ID="lbtnLast" runat="server" οnclick="lbtnLast_Click">最后一页</asp:LinkButton>
</td>
<td nowrap width="6%">
跳到第
</td>
<td nowrap width="4%">
<asp:TextBox ID="txtPage" runat="server" Columns="2" Width="16pt"></asp:TextBox>
</td>
<td width="6%">
页
</td>
<td width="6%">
<asp:ImageButton ID="btnGo" runat="server" ImageUrl="~/images/go.gif"
οnclick="btnGo_Click"></asp:ImageButton>
</td>
<td width="5%">
</td>
</tr>
</table>