我使用Mike Brind的指南来设置分页,这是一种享受.我还使用bootstrap在页面底部创建一个更好看的页面导航.你能告诉我我需要做什么,以便NEXT和PREV按钮工作吗?我想它就像i 1和i-1,但我还没
编辑代码:
//Paging var pageSize = 6; var totalPages = 0; var count = 0; var page = UrlData[0].IsInt() ? UrlData[0].AsInt() : 1; var offset = (page -1) * pageSize; var db = Database.Open("StayInFlorida"); var sql = "Select Count(*) From PropertyInfo "; count = (int)db.QueryValue(sql); totalPages = count/pageSize; if(count % pageSize > 0){ totalPages += 1; } sql = "SELECT PropertyName, PropertyID, ResortName, NumBedrooms, NumBathrooms, NumSleeps, BriefDescription, PrimaryImage FROM PropertyInfo "+ "Order By PropertyID OFFSET @0 ROWS FETCH NEXT @1 ROWS ONLY;"; var result = db.Query(sql, offset, pageSize); <!--Pagination Start--> <div class="pagination pagination-centered"> <ul> @{ if(page > 1){ <li><a href="/portfolio1/@(page-1)">Prev</a></li> } for (var i = 1; i < totalPages + 1; i++){ <li><a href="/portfolio1/@i">@i</a></li> } if(page > 1){ <li><a href="/portfolio1/@(page + 1)">Next</a></li> } } </ul> </div> <br> <!--Pagination Finish-->如果有下一页或上一页要去,大概你只想要一个Next或Previous按钮出现?如果是这样,并且假设您正在跟踪名为page的变量中的当前页码,那么您可以这样做:
<!--Pagination Start--> <div class="pagination pagination-large"> <ul> @if(page > 1){ <li><a href="/portfolio1/@(page-1)">Prev</a></li> } for (var i = 1; i < totalPages + 1; i++){ <li><a href="/portfolio1/@i">@i</a></li> } if(page < totalPages){ <li><a href="/portfolio1/@(page + 1)">Next</a></li> } </ul> </div> <br> <!--Pagination Finish-->