MVC下
後台代碼
代碼如下:
public ActionResult sys(string page)
{
if (page == null)
{
string sql = "select top
* from dingdinfo ORDER BY dingdh desc";
ViewData["ds"] = dr
resultSet(sql
"dingdinfo");
}
if (page != null)
{
int pageSL = Convert
ToInt
(page);
string sql = "select top
* from dingdinfo where id not in (select top " + (pageSL
) *
+ " id from dingdinfo order by dingdh desc )ORDER BY dingdh desc";
ViewData["ds"] = dr
resultSet(sql
"dingdinfo");
}
//計算pageCount
string sql
= "select * from dingdinfo";
int pageCount = dr
resultCount(sql
"dingdinfo");
int Chu = Convert
ToInt
(pageCount /
);
int yuS = Convert
ToInt
(pageCount %
);
if (pageCount >
)
{
int pageJG = Chu;
if (yuS !=
)
{
pageJG = Chu +
;
ViewData["jg"] = pageJG;
}
else
{
ViewData["jg"] = pageJG;
}
}
return View();
}
頁面顯示
JS代碼
代碼如下:
<script type="text/javascript">
//分頁
function Page(id) {
window
location = "/bookIndex/sys/?page=" + id;
}
</script>
HTML代碼
代碼如下:
<td>
<% int count =Convert
ToInt
(ViewData["jg"]);
if (count !=
)
{
for (int i =
; i <=count; i++)
{ %>
<a href = "#" onclick="Page(<%:i%>)"><%:i%></a>
<% }
}%>
</td>
From:http://tw.wingwit.com/Article/program/net/201311/14123.html