2 using System.Collections.G " /> √8天堂资源地址中文在线,国产视频精品视频,日韩在线精品

中文字幕日韩一区二区_国产一区二区av_国产毛片av_久久久久国产一区_色婷婷电影_国产一区二区精品

一個(gè)MVC分頁(yè)Helper

  本人寫的一個(gè)分頁(yè)Helper,支持普通分頁(yè)(也就是,首頁(yè)、上一頁(yè)、下一頁(yè)、末頁(yè)等),綜合分頁(yè)(普通分頁(yè)和數(shù)字分頁(yè)的綜合)。下面是分頁(yè)效果:

分頁(yè)代碼:

PagerHelper.cs

代碼  1 using System;
  2  using System.Collections.Generic;
  3 using System.Collections.Specialized;
  4 using System.Linq;
  5 using System.Web;
  6 using System.Text;
  7 using System.Web.Mvc;
  8 using System.Web.Routing;
  9 using System.Data.Objects.DataClasses;
 10 namespace System.Web.Mvc
 11 {
 12     public static class PagerHelper
 13     {
 14         /// 
 15         /// 分頁(yè)
 16         /// 
 17         /// 
 18         /// 分頁(yè)id
 19         /// 當(dāng)前頁(yè)
 20         /// 分頁(yè)尺寸
 21         /// 記錄總數(shù)
 22         /// 分頁(yè)頭標(biāo)簽屬性
 23         /// 分頁(yè)樣式
 24         /// 分頁(yè)模式
 25         /// 
 26         public static string Pager(this HtmlHelper helper, string id, int currentPageIndex, int pageSize, int recordCount, object htmlAttributes, string className,PageMode mode)
 27         {
 28             TagBuilder builder = new TagBuilder("table");
 29             builder.IdAttributeDotReplacement = "_";
 30             builder.GenerateId(id);
 31             builder.AddCssClass(className);
 32             builder.MergeAttributes(new RouteValueDictionary(htmlAttributes));
 33             builder.InnerHtml = GetNormalPage(currentPageIndex, pageSize, recordCount,mode);
 34             return builder.ToString();
 35         }
 36         /// 
 37         /// 分頁(yè)
 38         /// 
 39         /// 
 40         /// 分頁(yè)id
 41         /// 當(dāng)前頁(yè)
 42         /// 分頁(yè)尺寸
 43         /// 記錄總數(shù)
 44         /// 分頁(yè)樣式
 45         /// 
 46         public static string Pager(this HtmlHelper helper, string id, int currentPageIndex, int pageSize, int recordCount, string className)
 47         {
 48             return Pager(helper, id, currentPageIndex, pageSize, recordCount, null, className,PageMode.Normal);
 49         }
 50         /// 
 51         /// 分頁(yè)
 52         /// 
 53         /// 
 54         /// 分頁(yè)id
 55         /// 當(dāng)前頁(yè)
 56         /// 分頁(yè)尺寸
 57         /// 記錄總數(shù)
 58         /// 
 59         public static string Pager(this HtmlHelper helper,string id,int currentPageIndex,int pageSize,int recordCount)
 60         {
 61             return Pager(helper, id, currentPageIndex, pageSize, recordCount,null);
 62         }
 63         /// 
 64         /// 分頁(yè)
 65         /// 
 66         /// 
 67         /// 分頁(yè)id
 68         /// 當(dāng)前頁(yè)
 69         /// 分頁(yè)尺寸
 70         /// 記錄總數(shù)
 71         /// 分頁(yè)模式
 72         /// 
 73         public static string Pager(this HtmlHelper helper, string id, int currentPageIndex, int pageSize, int recordCount,PageMode mode)
 74         {
 75             return Pager(helper, id, currentPageIndex, pageSize, recordCount, null,mode);
 76         }
 77         /// 
 78         /// 分頁(yè)
 79         /// 
 80         /// 
 81         /// 分頁(yè)id
 82         /// 當(dāng)前頁(yè)
 83         /// 分頁(yè)尺寸
 84         /// 記錄總數(shù)
 85         /// 分頁(yè)樣式
 86         /// 分頁(yè)模式
 87         /// 
 88         public static string Pager(this HtmlHelper helper, string id, int currentPageIndex, int pageSize, int recordCount,string className, PageMode mode)
 89         {
 90             return Pager(helper, id, currentPageIndex, pageSize, recordCount, null,className,mode);
 91         }
 92         /// 
 93         /// 獲取普通分頁(yè)
 94         /// 
 95         /// 
 96         /// 
 97         /// 
 98         /// 
 99         private static string GetNormalPage(int currentPageIndex, int pageSize, int recordCount,PageMode mode)
100         {
101             int pageCount = (recordCount%pageSize ==0?recordCount/pageSize:recordCount/pageSize+1);
102             StringBuilder url = new StringBuilder();
103             url.Append(HttpContext.Current.Request.Url.AbsolutePath+"?page={0}");
104             NameValueCollection collection = HttpContext.Current.Request.QueryString;
105             string[] keys = collection.AllKeys;
106             for (int i = 0; i < keys.Length; i++)
107             {
108                 if (keys[i].ToLower() != "page")
109                     url.AppendFormat("&{0}={1}", keys[i], collection[keys[i]]);
110             }
111             StringBuilder sb = new StringBuilder();
112             sb.Append("");
113             sb.AppendFormat("總共{0}條記錄,共{1}頁(yè),當(dāng)前第{2}頁(yè)  ", recordCount, pageCount, currentPageIndex);
114             if (currentPageIndex == 1)
115                 sb.Append("首頁(yè) ");
116             else
117             {
118                 string url1 = string.Format(url.ToString(), 1);
119                 sb.AppendFormat("首頁(yè) ", url1);
120             }
121             if (currentPageIndex > 1)
122             {
123                 string url1 = string.Format(url.ToString(), currentPageIndex - 1);
124                 sb.AppendFormat("上一頁(yè) ", url1);
125             }
126             else
127                 sb.Append("上一頁(yè) ");
128             if(mode == PageMode.Numeric)
129                 sb.Append(GetNumericPage(currentPageIndex,pageSize,recordCount,pageCount,url.ToString()));
130             if (currentPageIndex < pageCount)
131             {
132                 string url1 = string.Format(url.ToString(), currentPageIndex+1);
133                 sb.AppendFormat("下一頁(yè) ", url1);
134             }
135             else
136                 sb.Append("下一頁(yè) ");
137 
138             if (currentPageIndex == pageCount)
139                 sb.Append("末頁(yè) ");
140             else
141             {
142                 string url1 = string.Format(url.ToString(), pageCount);
143                 sb.AppendFormat("末頁(yè) ", url1);
144             }
145             return sb.ToString();
146         }
147         /// 
148         /// 獲取數(shù)字分頁(yè)
149         /// 
150         /// 
151         /// 
152         /// 
153         /// 
154         /// 
155         /// 
156         private static string GetNumericPage(int currentPageIndex, int pageSize, int recordCount, int pageCount,string url)
157         {
158             int k = currentPageIndex / 10;
159             int m = currentPageIndex % 10;
160             StringBuilder sb = new StringBuilder();
161             if (currentPageIndex / 10 == pageCount / 10)
162             {
163                 if (m == 0)
164                 {
165                     k--;
166                     m = 10;
167                 }
168                 else
169                     m = pageCount%10;
170             }
171             else
172                 m = 10;
173             for (int i = k * 10 + 1; i <= k * 10 + m; i++)
174             {
175                 if (i == currentPageIndex)
176                     sb.AppendFormat("{0} ", i);
177                 else
178                 {
179                     string url1 = string.Format(url.ToString(), i);
180                     sb.AppendFormat("{1} ",url1, i);
181                 }
182             }
183             
184             return sb.ToString();
185         }
186     }
187     /// 
188     /// 分頁(yè)模式
189     /// 
190     public enum PageMode
191     {
192         /// 
193         /// 普通分頁(yè)模式
194         /// 
195         Normal,
196         /// 
197         /// 普通分頁(yè)加數(shù)字分頁(yè)
198         /// 
199         Numeric
200     }
201 }
202 

NET技術(shù)一個(gè)MVC分頁(yè)Helper,轉(zhuǎn)載需保留來(lái)源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 日韩av一区二区在线 | 99精品在线免费观看 | 午夜婷婷激情 | 国产一区2区 | 成人在线免费观看 | 韩日一区 | 伊人春色成人网 | 国产一区二区久久 | 日本在线中文 | 欧美电影免费网站 | 国产精品一区二区三区99 | 国产精品欧美一区二区三区 | 成人久久18免费 | 一级a性色生活片久久毛片 一级特黄a大片 | 亚洲欧美日韩久久久 | 日韩av一区在线观看 | 一区二区播放 | 免费高清成人 | 婷婷精品 | 婷婷福利| 日韩精品在线视频免费观看 | 欧美极品在线视频 | 亚洲一区二区三区在线播放 | 日韩综合在线 | 在线国产一区 | 99精品久久 | 高清国产一区二区 | 国产二区视频 | 久久久精品一区二区 | 日本成人区 | 欧美视频在线观看 | 亚洲看片网站 | 欧美日韩一区在线观看 | 亚洲视频在线免费观看 | 日日天天 | 美女福利网站 | a级黄色片视频 | 羞羞视频免费在线 | www.色综合| 欧美性视频在线播放 | 国产一区二|