我在ASP.NET页面中有一个基本的<ul>
<li>
结构。现在我在这个<li>
中获得动态记录,我的问题是,当用户点击下一个按钮时,它应该检查最后一页,并相应地显示一条警告消息,如果已到达最后一页。
我在jQuery中获取totalPages,当我发出警报时,我收到了TotalPage
的消息,但是当我在if
条件下编写相同的代码时,它没有评估。下面是我的JavaScript函数。
var totalPages = -1;
function MostPopularSlideShows(currentPage, pager, mostpopular_data) {
$.ajax({
type: "POST",
url: "SlideShowAdmin/Ajax/SlideShow.aspx/MostPopularSlideList",
dataType: "json",
contentType: "application/json",
data: "{\"CurrentPage\":'" + currentPage + "'}",
success: function (data) {
var result = data.d;
var totalPages = result[0].TotalPages;
//alert(totalPages); This works fine.
if (currentPage > totalPages) //Here it never evaluates
{
alert("You have reached last page");
currentPage -= 1;
}
else {
$("#" + pager).html(currentPage + "/" + result[0].TotalPages);
$("#" + mostpopular_data).html("");
$.each(result, function (index, item) {
$("#" + mostpopular_data).append("<li><img src=\"images/most_popr_pic1.jpg\" width=\"153\" height=\"90\" alt=\"\" class=\"floatleft\" /><h6>" + item.SlideShowName + "</h6><h3><a href=\"#\">" + item.Title + "</a></h3><h4>" + item.Description + "</h4></li>");
})
}
},
error: function (data) {
alert("Cannot Get Most Popular SlideShow, Server Threw below error:\n" + data.responseText);
}
});
}
以下是我的Ajax功能。
[WebMethod]
public static SlideList[] MostPopularSlideList(int CurrentPage)
{
List<SlideList> list = new List<SlideList>();
DataSet d = SqlHelper.ExecuteAdapterForDataSet("user_MostPopularSlideShow", new SqlParameter[] { new SqlParameter("@PortalID", PortalId), new SqlParameter("@CurrentPage", CurrentPage) }, CommandType.StoredProcedure);
foreach (DataRow r in d.Tables[0].Rows)
{
SlideList _slide = new SlideList();
_slide.Id = Convert.ToInt32(r["Id"]);
_slide.SlideShowId = Convert.ToInt32(r["SlideShowId"]);
_slide.Description = r["SlideDescription"].ToString();
_slide.CreatedDate = (r["CreatedDate"]).ToString();
_slide.Thumbnail = r["Thumbnail"].ToString();
_slide.Total = Convert.ToInt32(d.Tables[1].Rows[0]["TotalRows"]);
_slide.TotalPages = Convert.ToInt32(d.Tables[1].Rows[0]["TotalPages"]);
_slide.Title = r["SlideTitle"].ToString();
_slide.SlideShowName = r["SlideShowName"].ToString();
list.Add(_slide);
}
return list.ToArray();
}
为什么不评估totalPages?
答案 0 :(得分:0)
实际上,我认为以下代码块永远不会执行。
if (currentPage > totalPages) //Here it never evaluates
{
alert("You have reached last page");
currentPage -= 1;
}
由于current page
最多可以totalPages
,因此可以进行等式检查,如:
if (currentPage == totalPages) //Here it never evaluates
{
alert("You have reached last page");
currentPage -= 1;
}