首页 > 代码库 > NVelocity分页时判断首页前一页后一页末页的详细
NVelocity分页时判断首页前一页后一页末页的详细
共$Data.TotalCount个/$Data.PageNum页
#if($Data.PageNum==1)
<span class="disabled"> << </span>
<span class="disabled"> < </span>
#else
<a href="http://www.mamicode.com/StuList.ashx?PageNum=1"> << </a>
#end
#if($Data.PageNum>1)
<a href="http://www.mamicode.com/StuList.ashx?PageNum=$Data.FrontPage"> < </a>
#end
#foreach($page in $Data.PageData)
#if($page.CurrentNum==$Data.PageNum)
<span class="current">$page.CurrentNum</span>
#else
<a href="http://www.mamicode.com/$page.href">$page.CurrentNum</a>
#end
#end
#if($Data.PageNum<$Data.PageCount)
#set($NextPage=$Data.PageNum+1)
<a href="http://www.mamicode.com/StuList.ashx?PageNum=$NextPage"> > </a>
#end
#if($Data.PageNum==$Data.PageCount)
<span class="disabled"> > </span>
<span class="disabled"> >> </span>
#else
<a href="http://www.mamicode.com/StuList.ashx?PageNum=$Data.PageCount"> >> </a>
#end
后台ashx部分代码
int pageNum = 1;
if (context.Request["PageNum"] != null)
{
pageNum = Convert.ToInt32(context.Request["PageNum"]);
}
int totalCount = (int)SqlHelper.ExecuteScalar("select count(*) from T_StuReq where IsDel=‘0‘");
int pageCount = (int)Math.Ceiling(totalCount / 5.0);
DataTable dt = SqlHelper.ExecuteDataTable(@"select * from( select s.requireId , s.Time , c.CName,s.requireAddress,s.requireSex,s.requirePrice,s.SEmail,s.requireInfo,row_number() over (order by s.requireId desc) as num from T_StuReq s left join T_Course c on s.CId=c.CId where s.IsDel=‘0‘)as s
where s.num between @Start and @End",
new SqlParameter("@Start", (pageNum - 1) * 5 + 1),
new SqlParameter("@End", pageNum * 5));
object[] pageData = http://www.mamicode.com/new object[pageCount];
for (int i = 0; i < pageCount; i++)
{
pageData[i] = new { href = "http://www.mamicode.com/StuList.ashx?PageNum=" + (i + 1), CurrentNum = (i + 1) };
}
int frontPage = pageNum - 1;
var data = http://www.mamicode.com/new { Info ="", Person = dt.Rows, TotalCount = totalCount, PageNum = pageNum, PageData = http://www.mamicode.com/pageData, PageCount = pageCount, FrontPage = frontPage };
string html = NvHelper.RenderHtml("Front/StuList.html", data);