-1
我在ASP.NET頁面中有一個基本的<ul>
<li>
結構。現在我在這個<li>
中獲得了動態記錄,我的問題是,當用戶點擊下一個按鈕時,它應該檢查最後一頁,並相應地顯示一條警告消息,如果最後一頁已經達到。使用jQuery導航Ajax
我得到了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?
當前頁==總頁數? – 2012-04-24 19:25:45