前台:<body>
<form id="form1" runat="server">
<div>
<table border="1" width="1000">
<tr>
<td>编号</td>
<td> 影片名称</td>
<td>主要演员</td>
<td>产地</td>
<td>上映时间</td>
</tr>
<% foreach (var movie in movieList)
{%>
<tr>
<td><%=movie.Id%></td>
<td><%=movie.MovieName%></td>
<td><%=movie.Impersonator %></td>
<td><%=movie.Area %></td>
<td><%=movie.ModfiyDate %></td>
</tr>
<%}
%>
<tr>
<td colspan="5" style="text-align:center">
<a href="Split.aspx?current=1&&operate=first">首页</a>
<a href="Split.aspx?current=<%=currentPage %>&&operate=up">上一页</a>
<a href="Split.aspx?current=<%=currentPage %>&&operate=down">下一页</a>
<a href="Split.aspx?current=<%=pageCount %>&&operate=last">最后一页</a>
</td>
</tr>
</table>
</div>
</form>
</body>
后台:public partial class Split : System.Web.UI.Page
{
public static int currentPage = 0; //当前页
public IList<Movie> movieList = null; //每页显示的数据集合
public int pageCount = 0;//一共要分的页数
protected void Page_Load(object sender, EventArgs e)
{
int allCount = new MovieDal().getAllCount();
//得到页数的值 20:每页显示的条数
if (allCount %20 == 0)
{
pageCount = allCount / 20;
}
else
{
pageCount = allCount / 20 + 1;
}
string strCurrentPage = Request.QueryString["current"];
//第一次加载进来 strCurrentPage=null; 首先给它一个默认值
if (strCurrentPage ==null)
{
currentPage = 1;
}
else
{
currentPage = Convert.ToInt32(strCurrentPage);
}
//从前台获得要操作的类型
string operate = Request.QueryString["operate"];
if (operate=="first")
{
currentPage = 1;
}
else if (operate == "up")
{
if (currentPage>1)
{
currentPage--;
}
}
else if (operate == "down")
{
if (currentPage < pageCount)
{
currentPage++;
}
}
else if (operate == "last")
{
currentPage = pageCount;
}
else
{
currentPage = 1;
}
movieList = new MovieDal().getMoive(currentPage, 20);
}
}