jquery.pagination.js使用

直接上代码:

 1     <script type="text/javascript">
 2         var pageIndex = 1; //页面索引初始值
 3         var pageSize = 10; //每页显示条数初始化,修改显示条数,修改这里即可
 4         // 默认什么当前用户所在的城市
 5         $().ready(function () {
 6             getCarBrandPrice(pageIndex, pageSize);
 7         });
 8         // 获取车型价格列表
 9         function getCarBrandPrice(pageIndex,pageSize ) {
10             $(".cmain").remove();
11             $.ajax({
12                 url: "asyncHandler.ashx?cmd=GetCarPriceLook&CarStalls=" + $("#hidCarStalls").val() + "&AreaID=" + $("#hidCityID").val()
13                 + "&MinPrice=" + $("#minPrice").val() + "&MaxPrice=" + $("#maxPrice").val() + "&OrderBy=" + $("#hidOrderBy").val()
14                 + "&CarBrandID=" + $("#hidCarBrandID").val() + "&r=" + Math.random() + "&pageIndex=" + pageIndex + "&pageSize=" + pageSize,
15                 success: function (response) {
16                     if (response!=null&&response.totalCount > 0) {
17 //                      $(".cmain").remove();
18 //                      $("#carlistdiv").append(BuildCarMain(response));
19                         $(".cmain").remove();
20                         $("#carlistdiv").append(BuildCarMain(response));
21                         $("#Pagination").pagination(response.totalCount, {
22                             callback: PageCallback, //PageCallback() 为翻页调用次函数。
23                             prev_text: "« 上一页",
24                             next_text: "下一页 »",
25                             items_per_page: pageSize,
26                             num_display_entries: 5, //连续分页主体部分分页条目数
27                             current_page: pageIndex - 1 //当前页索引
28                         });
29                     }
30                     else {
31                         $(".cmain").remove();
32                         $("#carlistdiv").append("<div class=\"cmain\" style='color:red;text-align:center;font-size:14;'>对不起,没有符合您所需要的车型!</div>");
33                     }
34                 }
35             });
36         }
37 
38         // 分页控件回调事件
39         function PageCallback(index, jq) {
40             getCarBrandPrice(index+1, pageSize);
41         }
查看代码

HTML代码:

1                         <div id="carlistdiv" class="car_list" runat="server">
2                         </div>
3                         <div id="Pagination" class="ui-paging"></div>
查看代码

C#后台代码:

        private string GetCarPriceLook(HttpContext context)
        {

            AnonCarBrandInfoFilter filter = new AnonCarBrandInfoFilter();
            filter.sortMode = string.IsNullOrEmpty(context.Request["OrderBy"]) ? "Asc" : TypeParse.ToStr(context.Request["OrderBy"]);
            filter.pageIndex = TypeParse.ToInt(context.Request["pageIndex"]);
            filter.pageSize = TypeParse.ToInt(context.Request["pageSize"]);

            IList<AnonCarBrandInfo> CarBrandlist = B_Car.Instance.GetListForLook(filter);
            if (filter.pageIndex > 0)//
            {
                CarBrandlist = CarBrandlist .Skip((filter.pageIndex - 1) * filter.pageSize).Take(filter.pageSize).ToList(); ;
            }
            return JsonConvert.SerializeObject(new
            {
                DataList = CarBrandlist ,
                totalCount = filter.totalCount
            });
        }

 

 

posted @ 2013-10-28 09:49  wangjj89621  阅读(1774)  评论(0编辑  收藏  举报