1 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Fenye.aspx.cs" Inherits="WebApplication1.Fenye" %>
2
3 <!DOCTYPE html>
4
5 <html xmlns="http://www.w3.org/1999/xhtml">
6 <head runat="server">
7 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
8 <title></title>
9 <style type="text/css">
10 .pager_manu .pageinfo {
11 float: right;
12 }
13
14 .pager_manu A {
15 float: left;
16 /*BORDER: #8db5d7 1px solid; */
17 PADDING-BOTTOM: 5px;
18 MARGIN-left: 2px;
19 MARGIN-right: 2px;
20 PADDING-LEFT: 1px;
21 PADDING-RIGHT: 1px;
22 COLOR: #000;
23 TEXT-DECORATION: none;
24 PADDING-TOP: 1px;
25 }
26
27 .pager_manu A:hover {
28 /*BORDER: red 1px solid; */
29 /*COLOR: #666; */
30 text-decoration: underline;
31 }
32
33 .pager_manu A:active {
34 /*BORDER: #999 1px solid; */
35 COLOR: #666;
36 }
37
38 .pager_manu .current {
39 float: left;
40 /*BORDER: #e89954 1px solid;*/
41 PADDING-BOTTOM: 1px;
42 MARGIN-left: 2px;
43 MARGIN-right: 2px;
44 PADDING-LEFT: 1px;
45 PADDING-RIGHT: 1px;
46 COLOR: #000;
47 FONT-WEIGHT: bold;
48 PADDING-TOP: 1px;
49 color: #ff0000;
50 /*background-color:#ffca7d;*/
51 }
52
53 .pager_manu .disable {
54 cursor: default;
55 COLOR: #999;
56 text-decoration: none;
57 }
58
59 .pager_manu .summary {
60 float: right;
61 margin-right: 2px;
62 /*COLOR: #036cb4;*/
63 color: #000000;
64 PADDING-BOTTOM: 1px;
65 MARGIN: 2px;
66 PADDING-LEFT: 2px;
67 PADDING-RIGHT: 2px;
68 TEXT-DECORATION: none;
69 PADDING-TOP: 1px;
70 }
71
72 .pager_manu .pagetext {
73 float: left;
74 cursor: pointer;
75 /*BORDER: #bbb 1px solid; */
76 PADDING-BOTTOM: 1px;
77 MARGIN: 2px;
78 PADDING-LEFT: 1px;
79 PADDING-RIGHT: 1px;
80 PADDING-TOP: 1px;
81 }
82
83 .pager_manu .pageShowNum {
84 color: blue;
85 }
86 </style>
87 </head>
88 <body>
89
90 <form id="form1" runat="server">
91 <div>
92 <asp:Repeater ID="Repeater1" runat="server">
93 <HeaderTemplate>
94 <table border="0" cellspace width="100%" class="mytable newTable">
95 <thead>
96 <tr style="font-weight: bold; line-height: 25px; height: 25px;">
97 <td class="brs" width="3%" nowrap="" align="center">
98 <strong>序号</strong>
99 </td>
100 <td class="brs" width="3%" style="text-align:center;">
101
102 <asp:CheckBox ID="CheckBox1" runat="server" ToolTip="全选" onclick="checkss(this);" />
103
104 </td>
105 <td class="brs" >
106 <strong>文件名称</strong>
107 </td>
108 <td class="brs" width="10%" >
109 <strong>更改名称</strong>
110 </td>
111 <td class="brs" width="10%">
112 <strong>文件大小</strong>
113 </td>
114 <td class="brs" width="10%" >
115 <strong>上传人</strong>
116 </td>
117 <td class="brs" width="15%" style="text-align: center;">
118 <strong>创建时间</strong>
119 </td>
120 <td class="brs" width="5%">
121 <strong>排序号</strong>
122 </td>
123 </tr>
124 </thead>
125 <tbody>
126 </HeaderTemplate>
127 <ItemTemplate>
128 <tr id='tr_<%# DataBinder.Eval(Container.DataItem, "FGBH")%>'>
129 <td style="text-align: center; color: Blue;">
130 <%#Container.ItemIndex + 1 + pageNav1.PageSize * (pageNav1.CurrentPageIndex - 1) %>
131 </td>
132 <td style="color: Blue; text-align:center;">
133 <input type="checkbox" id="CheckBox11" class="checkBox" guid='<%# DataBinder.Eval(Container.DataItem, "FGBH") %>' />
134 </td>
135 <td>
136 <div runat="server" id="divpp" style="cursor: pointer; color: #6300FF;">
137 <%# Eval("FGMC")%>
138 <%-- <asp:Literal ID="ltDown" runat="server"></asp:Literal>--%>
139 </div>
140 </td>
141 <td></td>
142 <td></td>
143 <td style="text-align: center;">
144 <%# Eval("XGR")%>
145 </td>
146 <td style="text-align: center;">
147 <%# Eval("CJSJ")%>
148 </td>
149 <td style="text-align: center;">
150 <%# Eval("PXM")%>
151 </td>
152 </tr>
153 </ItemTemplate>
154 <FooterTemplate>
155 </tbody> </table>
156 </FooterTemplate>
157 </asp:Repeater>
158 </div>
159 <div class="pagingTopDiv">
160 <oswc:OsPageNavigation ID="pageNav1" runat="server" OnPageIndexChanged="pageNav_PageChanged">
161 </oswc:OsPageNavigation>
162 </div>
163 </form>
164 </body>
165 </html>
1 using Oceansoft.Net.Bll.Common;
2 using SubSonic;
3 using System;
4 using System.Collections.Generic;
5 using System.Data;
6 using System.Linq;
7 using System.Text;
8 using System.Web;
9 using System.Web.UI;
10 using System.Web.UI.WebControls;
11
12 namespace WebApplication1
13 {
14 public partial class Fenye : System.Web.UI.Page
15 {
16 protected void Page_Load(object sender, EventArgs e)
17 {
18 if (!IsPostBack)
19 {
20 LoadInfo(1);
21
22 }
23 }
24
25 public void LoadInfo(int pageIndex)
26 {
27 PagingEntity_CusMS pe = new PagingEntity_CusMS();
28 pe.PageIndex = pageIndex;
29 pageNav1.CurrentPageIndex = pe.PageIndex;
30 pe.PageSize = 10;
31 DataTable dt = GetContractMain(pe);
32 this.Repeater1.DataSource = dt;
33 this.Repeater1.DataBind();
34 CommonBind.BindPageNavigation(pageNav1, pe.PageSize, pe.TotalRecords, pageIndex);
35 }
36
37 protected void pageNav_PageChanged(object src, EventArgs e)
38 {
39 LoadInfo(pageNav1.CurrentPageIndex);
40 }
41
42 public DataTable GetContractMain(PagingEntity_CusMS pe)
43 {
44 StringBuilder sblder = new StringBuilder();
45 string sql = "";
46 sblder.Append(" SELECT FGBH AS Guid, * from T_YDZF_FLFG where 1=1 ");
47
48 sql = pe.GetPagingSql_SQLServer(sblder.ToString());
49 DataTable dt = new DataTable();
50
51 QueryCommand qc = new InlineQuery().GetCommand(sql, pe.Paras.ToArray());
52 dt = DataService.GetDataSet(qc).Tables[0];
53 return dt;
54 }
55 }
56 }
1 using System;
2 using System.Collections.Generic;
3 using System.Collections.Specialized;
4 using System.ComponentModel;
5 using System.Linq;
6 using System.Web;
7 using System.Web.UI;
8
9 namespace WebApplication1
10 {
11 public class PageChangedEventArgs : EventArgs
12 {
13 /// <summary>
14 ///
15 /// </summary>
16 public int NewPagesIndex;
17 /// <summary>
18 ///
19 /// </summary>
20 public int NewPageIndex;
21
22 }
23 /// <summary>
24 ///
25 /// </summary>
26 [DefaultProperty("CurrentPageIndex"),
27 ToolboxData("<oswc:OsPageNavigation runat=server></oswc:OsPageNavigation>")]
28 public class OsPageNavigation : Control, IPostBackDataHandler, IPostBackEventHandler//, ICallbackEventHandler
29 {
30 ///<summary>
31 ///委托页面索引事件
32 ///</summary>
33 public delegate void PageChangedEventHandler(object sender, PageChangedEventArgs e);
34
35 /// <summary>
36 /// 分页事件
37 /// </summary>
38 public event PageChangedEventHandler PageIndexChanged;
39
40 # region << Public Properties >>
41 ///<summary>
42 ///样式属性
43 ///</summary>
44 [Bindable(false),
45 Category("Style"),
46 DefaultValue("pager_manu")]
47 private string CssClass
48 {
49 get
50 {
51 return "pager_manu";
52 }
53 }
54
55 private int totalCount = -1;
56 ///<summary>
57 ///记录总数
58 ///</summary>
59 [Bindable(false),
60 Category("TotalCount"),
61 DefaultValue(0)]
62 public int RecordCount
63 {
64 get
65 {
66 if (totalCount == -1)
67 {
68 if (this.IsNumeric(ViewState["TotalCount"]))
69 {
70 totalCount = (int)ViewState["TotalCount"];
71 }
72 else
73 {
74 totalCount = 0;
75 }
76 }
77 return totalCount;
78 }
79 set
80 {
81 ViewState["TotalCount"] = value;
82 totalCount = value;
83 }
84 }
85
86 private int pageSize = -1;
87 ///<summary>
88 ///分页大小
89 ///</summary>
90 [Bindable(false),
91 Category("PageSize"),
92 DefaultValue(15)]
93 public int PageSize
94 {
95 get
96 {
97 if (pageSize == -1)
98 {
99 if (this.IsNumeric(ViewState["PageSize"]))
100 {
101 pageSize = (int)ViewState["PageSize"];
102 }
103 else
104 {
105 pageSize = 15;
106 }
107 }
108 return pageSize;
109 }
110 set
111 {
112 ViewState["PageSize"] = value;
113 pageSize = value;
114 }
115 }
116
117 private int currentPagesIndex = -1;
118 /// <summary>
119 /// 当前页群索引
120 /// </summary>
121 [Bindable(false),
122 Category("CurrentPagesIndex"),
123 DefaultValue(0)]
124 public int CurrentPagesIndex
125 {
126 get
127 {
128 if (currentPagesIndex == -1)
129 {
130 if (this.IsNumeric(ViewState["CurrentPagesIndex"]))
131 {
132 currentPagesIndex = (int)ViewState["CurrentPagesIndex"];
133 }
134 else
135 {
136 currentPagesIndex = 0;
137 }
138 }
139 return currentPagesIndex;
140 }
141 set
142 {
143 ViewState["CurrentPagesIndex"] = value;
144 //currentPagesIndex = value;
145 if (currentPageIndex != 1)
146 currentPagesIndex = value;
147 else
148 currentPagesIndex = 0;
149 }
150
151 }
152
153 private int currentPageIndex = -1;
154 ///<summary>
155 ///当前页索引
156 ///</summary>
157 [Bindable(false),
158 Category("CurrentPageIndex"),
159 DefaultValue(1)]
160 public int CurrentPageIndex
161 {
162 get
163 {
164 if (currentPageIndex == -1)
165 {
166 if (this.IsNumeric(ViewState["CurrentPageIndex"]))
167 {
168 return (int)ViewState["CurrentPageIndex"];
169 }
170 else
171 {
172 return 1;
173 }
174 }
175 return currentPageIndex;
176 }
177 set
178 {
179 ViewState["CurrentPageIndex"] = value;
180 currentPageIndex = value;
181 }
182 }
183
184 ///<summary>
185 ///页群属性
186 ///</summary>
187 [Bindable(false),
188 Category("PaginationCount"),
189 DefaultValue(10)]
190 public int PaginationCount
191 {
192 get
193 {
194 return 10;
195 }
196 set
197 {
198 ;
199 }
200 }
201
202
203
204 ///// <summary>
205 ///// 是否为异步事件
206 ///// </summary>
207 //[Bindable(false),
208 // Category("IsAsync"),
209 // DefaultValue(0)]
210 //public bool IsAsync
211 //{
212 // set
213 // {
214
215 // ViewState["IsAsync"] = value;
216 // }
217 // get
218 // {
219 // if (null != ViewState["IsAsync"])
220 // {
221 // return Boolean.Parse(ViewState["IsAsync"].ToString());
222 // }
223 // else
224 // {
225 // return false;
226 // }
227 // }
228 //}
229
230 //private bool displayPageInfo = true;
231 /// <summary>
232 /// 是否显示分页信息
233 /// </summary>
234 [Bindable(false),
235 DefaultValue(true)]
236 public bool DisplayPageInfo
237 {
238 get
239 {
240 if (ViewState["DisplayPageInfo"] is bool)
241 {
242 return (bool)ViewState["DisplayPageInfo"];
243 }
244 else
245 {
246 return true;
247 }
248 }
249 set
250 {
251 ViewState["DisplayPageInfo"] = value;
252 }
253 }
254
255 #region <<分页控件按钮名称>>
256
257 ///<summary>
258 ///标记样式
259 ///</summary>
260 [Bindable(false),
261 Category("Text"),
262 DefaultValue("首页")]
263 private string FirstName
264 {
265 get
266 {
267 //return ViewState["FirstName"] == null ? "首页" : (string)ViewState["FirstName"];
268 return "首页";
269 }
270 //set
271 //{
272 // ViewState["FirstName"] = value;
273 //}
274 }
275
276
277 /// <summary>
278 /// 上一页
279 /// </summary>
280 [Bindable(false),
281 Category("Text"),
282 DefaultValue("上页")]
283 private string PreName
284 {
285 get
286 {
287 return "上页";
288 //return ViewState["PreName"] == null ? "上一页" : (string)ViewState["PreName"];
289 }
290 //set
291 //{
292 // ViewState["PreName"] = value;
293
294 //}
295 }
296
297 /// <summary>
298 /// 下一页
299 /// </summary>
300 [Bindable(false)]
301 [Category("Text")]
302 [DefaultValue("下页")]
303 private string NextName
304 {
305 get
306 {
307 return "下页";
308 //return ViewState["NextName"] == null ? "后一页" : (string)ViewState["NextName"];
309 }
310
311 //set
312 //{
313
314 // ViewState["NextName"] = value;
315
316 //}
317 }
318
319 ///<summary>
320 ///下一页
321 ///</summary>
322 [Bindable(false),
323 Category("Text"),
324 DefaultValue("尾页")]
325 private string LastName
326 {
327 get
328 {
329 return "尾页";
330 //return ViewState["LastName"] == null ? "最后页" : (string)ViewState["LastName"];
331 }
332
333 //set
334 //{
335
336 // ViewState["LastName"] = value;
337
338 //}
339 }
340
341 #endregion
342
343 # endregion
344
345 # region << Public Mothod >>
346 ///<summary>
347 ///当由类实现时,使服务器控件能够处理将窗体发送到服务器时引发的事件。
348 ///</summary>
349 ///<param name="e">所传递的参数</param>
350 public void RaisePostBackEvent(string e)
351 {
352 //当发生回送的时候改变控件当前索引
353 if (e == "top")
354 {
355 CurrentPageIndex = 1;
356 CurrentPagesIndex = 0;
357 }
358 else if (e == "last")
359 {
360 CurrentPageIndex = (RecordCount + PageSize - 1) / PageSize;
361
362 // CurrentPagesIndex = ((RecordCount + PageSize - 1) / PageSize + PaginationCount - 1) / PaginationCount - 1;
363
364 if (CurrentPageIndex < 1)
365 {
366 CurrentPageIndex = 1;
367 }
368 //if (CurrentPagesIndex < 0)
369 //{
370 // CurrentPagesIndex = 0;
371 //}
372 }
373 else if (e == "pre")
374 {
375 if (CurrentPageIndex > 1)
376 {
377 CurrentPageIndex--;
378
379 //if (CurrentPageIndex < CurrentPagesIndex * PaginationCount && CurrentPageIndex > 0)
380 //{
381 // CurrentPagesIndex--;
382 //}
383
384 //if (CurrentPageIndex % 10 == 0)
385 // CurrentPagesIndex = CurrentPageIndex / 10 - 1;
386
387 }
388 }
389 else if (e == "next")
390 {
391 if (CurrentPageIndex < (RecordCount + PageSize - 1) / PageSize)
392 {
393 CurrentPageIndex++;
394
395 //if (CurrentPageIndex > (CurrentPagesIndex + 1) * PaginationCount - 1 && CurrentPageIndex < RecordCount - 1)
396 //{
397
398 // CurrentPagesIndex++;
399 //}
400 }
401 }
402 else
403 {
404 CurrentPageIndex = int.Parse(e.ToString());
405 }
406
407 //发生回送事件时引发OnPageIndexChange事件
408 PageChangedEventArgs ev = new PageChangedEventArgs();
409 ev.NewPageIndex = CurrentPageIndex;
410 ev.NewPagesIndex = CurrentPagesIndex;
411 OnPageIndexChanged(this, ev);
412 }
413
414 ///<summary>
415 ///当由类实现时,为 ASP.NET 服务器控件处理回发数据。
416 ///</summary>
417 ///<param name="postDataKey">数据集合元素索引</param>
418 ///<param name="values">string 的排序集合</param>
419 ///<returns></returns>
420 public bool LoadPostData(string postDataKey, NameValueCollection values)
421 {
422 CurrentPageIndex = Int32.Parse(values[this.UniqueID].Split('|')[0]);
423
424 CurrentPagesIndex = Int32.Parse(values[this.UniqueID].Split('|')[1]);
425
426 return false;
427
428 }
429
430 ///<summary>
431 ///当页面索引改变,触发委托
432 ///</summary>
433 ///<param name="e"></param>
434 protected virtual void OnPageIndexChanged(object sender, PageChangedEventArgs e)
435 {
436 if (PageIndexChanged != null)
437 PageIndexChanged(sender, e);
438 }
439 # endregion
440
441 #region << override method >>
442
443 ///<summary>
444 ///将此控件呈现给指定的输出参数。
445 ///</summary>
446 ///<param name="output">要写出到的 HTML 编写器 </param>
447 protected override void Render(HtmlTextWriter output)
448 {
449 string Pagestring = ""; //定义页码呈现字符串
450 string Text = null; //输出主结构字符串变量定义
451 int NO = 0;
452 int allPages = (RecordCount + PageSize - 1) / PageSize; //总页数
453 int startPage = 0;
454 int endPage = PaginationCount;
455
456 //当页大小小于0时,还原为1,防止预算出现除0错误
457 if (!(PageSize > 0))
458 {
459 PageSize = 1;
460 }
461
462 if (DisplayPageInfo)
463 {
464 if (CurrentPageIndex > 5)
465 {
466 startPage = CurrentPageIndex - 5;
467 if (endPage < allPages)
468 {
469 endPage = CurrentPageIndex + 5;
470 }
471 else
472 {
473 endPage = allPages;
474 }
475
476 }
477 //计算出总页数,并循环输出页码
478 for (int i = startPage; i < endPage; i++)
479 {
480 //获得页群内页码
481 NO = PaginationCount * (CurrentPagesIndex) + i + 1;
482
483 if (NO <= allPages)
484 {
485 //判断页码是否为当前页
486
487 if (CurrentPageIndex != NO)
488 {
489 Pagestring += string.Format("<a href=\"javascript:{0}\" class='pagenumber'>{1}</a>",
490 Page.GetPostBackEventReference(this, (NO).ToString()), (NO).ToString());
491 }
492 //如果不是,页面部分无连接
493 else
494 {
495 Pagestring += "<span class='current pagenumber'>" + (NO).ToString() + "</span>";
496 }
497 }
498 }
499
500 if (!(Pagestring.Trim().Length > 0))
501 {
502 Pagestring = "";
503 }
504 }
505
506
507 //输出主结构
508 Text = string.Format("<div class=\"{0}\">", this.CssClass);
509
510 if (DisplayPageInfo)
511 {
512 int currentPageIndex = CurrentPageIndex;
513 int totalPageCount = RecordCount / PageSize + (RecordCount % PageSize > 0 ? 1 : 0);
514
515 if (currentPageIndex > totalPageCount)
516 currentPageIndex = totalPageCount;
517
518 int perPageCount = PageSize;
519 if (RecordCount >= PageSize)
520 {
521 if (CurrentPageIndex == RecordCount / PageSize + (RecordCount % PageSize > 0 ? 1 : 0))
522 {
523 perPageCount = RecordCount - (CurrentPageIndex - 1) * PageSize;
524 }
525 }
526 else
527 {
528 perPageCount = RecordCount;
529 }
530
531 Text += string.Format("<div class=\"summary\">共{2}条记录 当前 {0}/{1} 页</div>", CurrentPageIndex, RecordCount / PageSize + (RecordCount % PageSize > 0 ? 1 : 0), RecordCount);
532 // Text += string.Format("<div class=\"summary\">记录总数:<span class=\"pageShowNum\">{2}</span> 当前页:<span class=\"pageShowNum\">{0}</span> 总页数:<span class=\"pageShowNum\">{1}</span></div>", perPageCount, RecordCount / PageSize + (RecordCount % PageSize > 0 ? 1 : 0), RecordCount);
533
534 }
535 Text += "<div class='pageinfo'>";
536
537 if (CurrentPageIndex == 1)
538 {
539 Text += string.Format("<span class='pagetext disable'>{0}</span>", FirstName);
540 }
541 else
542 {
543 Text += string.Format("<a href=\"javascript:{0}\" class='pagetext'>{1}</a>", Page.GetPostBackEventReference(this, "top"), FirstName);
544 }
545
546 if (CurrentPageIndex > 1)
547 {
548 Text += string.Format("<a href=\"javascript:{0}\" class='pagetext'>{1}</a>", Page.GetPostBackEventReference(this, "pre"), PreName);
549 }
550 else
551 {
552 Text += string.Format("<span class='pagetext disable'>{0}</span>", PreName);
553 }
554
555 Text += "$Pagestring$";
556
557 if (CurrentPageIndex < (RecordCount + PageSize - 1) / PageSize)
558 {
559 Text += string.Format("<a href=\"javascript:{0}\" class=\"pagetext\">{1}</a>", Page.GetPostBackEventReference(this, "next"), NextName);
560 }
561 else
562 {
563 Text += string.Format("<span class='pagetext disable'>{0}</span>", NextName);
564 }
565
566
567 if (CurrentPageIndex == (RecordCount + PageSize - 1) / PageSize)
568 {
569 Text += string.Format("<span class='pagetext disable'>{0}</span>", LastName);
570 }
571 else
572 {
573 if (RecordCount < PageSize || RecordCount == PageSize)
574 {
575 Text += string.Format("<span class='pagetext disable'>{0}</span>", LastName);
576 }
577 else
578 {
579 Text += string.Format("<a href=\"javascript:{0}\" class='pagetext'>{1}</a>", Page.GetPostBackEventReference(this, "last"), LastName);
580 }
581 }
582 Text += "</div>";
583
584 Text += "</div><input type =\"hidden\" name=\"" + this.UniqueID + "\" value=\"" + this.CurrentPageIndex + "|" + this.CurrentPagesIndex + "\">";
585
586 //替换页码部分
587 Text = Text.Replace("$Pagestring$", Pagestring);
588 if (RecordCount == 0)
589 {
590 output.Write("");
591 }
592 else
593 {
594 output.Write(Text);
595 }
596 }
597
598 # region << 样式二 >>
599 /*
600 protected override void Render(HtmlTextWriter output)
601 {
602 string Pagestring = ""; //定义页码呈现字符串
603 string Text = null; //输出主结构字符串变量定义
604 int NO = 0;
605
606 //当页大小小于0时,还原为1,防止预算出现除0错误
607 if (!(PageSize > 0))
608 {
609 PageSize = 1;
610 }
611
612 if (DisplayPageInfo)
613 {
614 //计算出总页数,并循环输出页码
615 for (int i = 0; i < PaginationCount; i++)
616 {
617 //获得页群内页码
618 NO = PaginationCount * (CurrentPagesIndex) + i + 1;
619 if (NO <= (TotalCount + PageSize - 1) / PageSize)
620 {
621 //判断页码是否为当前页
622
623 if (CurrentPageIndex != NO)
624 {
625 Pagestring += string.Format("<li class=\"pagenumber\"><a onclick=\"javascript:{0}\" href='javascript:void(0)'>{1}</a> </li>",
626 Page.GetPostBackEventReference(this, (NO).ToString()), (NO).ToString());
627 //string.Format("turnPage({0})", (NO).ToString()), (NO).ToString());
628
629 }
630 //如果不是,页面部分无连接
631 else
632 {
633 Pagestring += "<li class='currentpagenumber'><span>" + (NO).ToString() + " </span></li>";
634 }
635 }
636 }
637
638 if (!(Pagestring.Trim().Length > 0))
639 {
640 Pagestring = "";
641 }
642 }
643
644
645 //输出主结构
646 Text = string.Format("<div class=\"{0}\"><ul>", this.CssClass);
647 if (CurrentPageIndex == 1)
648 {
649 Text += string.Format("<li class='first0'>{0}</li>", FirstName);
650 }
651 else
652 {
653 Text += string.Format("<li class='first'><a href=\"javascript:{0}\">{1}</a></li>", Page.GetPostBackEventReference(this, "top"), FirstName);
654 }
655
656 if (CurrentPageIndex > 1)
657 {
658 Text += string.Format("<li class='pre'><a href=\"javascript:{0}\">{1}</a></li>", Page.GetPostBackEventReference(this, "pre"), PreName);
659 }
660 else
661 {
662 Text += string.Format("<li class='pre0'>{0}</li>", PreName);
663 }
664
665 Text += "$Pagestring$";
666
667 if (CurrentPageIndex < (TotalCount + PageSize - 1) / PageSize)
668 {
669 Text += string.Format("<li class='next'><a href=\"javascript:{0}\">{1}</a></li>", Page.GetPostBackEventReference(this, "next"), NextName);
670 }
671 else
672 {
673 Text += string.Format("<li class='next0'>{0}</li>", NextName);
674 }
675
676
677 if (CurrentPageIndex == (TotalCount + PageSize - 1) / PageSize)
678 {
679 Text += string.Format("<li class='last0'>{0}</li>", LastName);
680 }
681 else
682 {
683 if (TotalCount < PageSize || TotalCount == PageSize)
684 {
685 Text += string.Format("<li class='last0'>{0}</li>", LastName);
686 }
687 else
688 {
689 Text += string.Format("<li class='last'><a href=\"javascript:{0}\">{1}</a></li>", Page.GetPostBackEventReference(this, "last"), LastName);
690 }
691 }
692
693 if (DisplayPageInfo)
694 {
695 Text += string.Format("<li class=\"summary\">当前 {0}/{1} 页</li>", CurrentPageIndex, TotalCount / PageSize + (TotalCount % PageSize > 0 ? 1 : 0));
696 }
697 Text += "</ul></div><input type = hidden name =" + this.UniqueID + " value = " + this.CurrentPageIndex + "|" + this.CurrentPagesIndex + ">";
698
699 //替换页码部分
700 Text = Text.Replace("$Pagestring$", Pagestring);
701 if (TotalCount == 0)
702 {
703 output.Write("");
704 }
705 else
706 {
707 output.Write(Text);
708 }
709 }
710 */
711 # endregion
712 # endregion
713
714 # region << Helpler >>
715
716 ///<summary>
717 ///判断是否为数字字符串
718 ///</summary>
719 ///<param name="str">需验证的字符串</param>
720 ///<returns>判断结果,符合条件为True,不符合条件为False</returns>
721 private bool IsNumeric(string str)
722 {
723
724 //判断是否为空
725 if (str == null || str.Length == 0)
726 {
727 return false;
728 }
729
730 //循环检查每个字符
731 foreach (char c in str)
732 {
733 if (!Char.IsNumber(c))
734 {
735 return false;
736 }
737 }
738 return true;
739 }
740
741 ///<summary>
742 ///判断是否为数字字符串
743 ///</summary>
744 ///<param name="obj">需验证的字符串</param>
745 ///<returns>判断结果,符合条件为True,不符合条件为False</returns>
746 private bool IsNumeric(object obj)
747 {
748 obj += "";
749 string str = obj.ToString();
750 //判断是否为空
751 if (str == null || str.Length == 0)
752 {
753 return false;
754 }
755
756 //循环检查每个字符
757 foreach (char c in str)
758 {
759 if (!Char.IsNumber(c))
760 {
761 return false;
762 }
763
764 }
765 return true;
766 }
767 # endregion
768
769 #region ICallbackEventHandler 成员
770 /// <summary>
771 ///
772 /// </summary>
773 /// <param name="pageIndex"></param>
774 public void RaiseCallbackEvent(string pageIndex)
775 {
776 int currentPageIndex = int.Parse(pageIndex);
777
778 if (currentPageIndex != CurrentPageIndex)
779 {
780 PageChangedEventArgs ev = new PageChangedEventArgs();
781 ev.NewPageIndex = int.Parse(pageIndex);
782
783 OnPageIndexChanged(this, ev);
784 }
785 CurrentPageIndex = currentPageIndex;
786 }
787
788 /// <summary>
789 ///
790 /// </summary>
791 private void RegisterClientScripts()
792 {
793 string turnPageScript = "function turnPage(pageIndex) { CallServer(pageIndex);}";
794 string receiveCallBackScript = "function ReceiveCallback(arg,context){ document.getElementById(context).innerHTML = arg; }";
795 string callbackReference = Page.ClientScript.GetCallbackEventReference(this, "arg", "ReceiveCallback", this.ClientID, false);
796
797 Page.ClientScript.RegisterClientScriptBlock(this.GetType(), this.ClientID + "TurnPageScript", turnPageScript, true);
798 Page.ClientScript.RegisterClientScriptBlock(this.GetType(), this.ClientID + "ReceiveCallBackScript", receiveCallBackScript, true);
799 Page.ClientScript.RegisterClientScriptBlock(this.GetType(), this.ClientID + "CallServer", string.Format("function CallServer(arg,context){{ {0} }}", callbackReference), true);
800 }
801 #endregion
802
803 #region IPostBackDataHandler 成员
804
805 /// <summary>
806 ///
807 /// </summary>
808 public void RaisePostDataChangedEvent()
809 {
810 }
811
812 #endregion
813 }
814 }
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Web;
5
6 namespace WebApplication1
7 {
8 public class CommonBind
9 {
10 public static void BindPageNavigation(OsPageNavigation pageNav, int pageSize, int recordCount, int pageIndex)
11 {
12 pageNav.PageSize = pageSize;
13 pageNav.RecordCount = recordCount;
14 pageNav.CurrentPageIndex = pageIndex;
15
16 //注意区分CurrentPageIndex和CurrentPagesIndex(多了个“s”)
17 if (pageNav.CurrentPageIndex == 1)
18 pageNav.CurrentPagesIndex = 0;
19 }
20 }
21 }
1 <?xml version="1.0" encoding="utf-8"?> 2 <!-- 3 有关如何配置 ASP.NET 应用程序的详细信息,请访问 4 http://go.microsoft.com/fwlink/?LinkId=169433 5 --> 6 <configuration> 7 <configSections> 8 <section name="SubSonicService" type="SubSonic.SubSonicSection, SubSonic" requirePermission="false"/> 9 <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --> 10 <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> 11 </configSections> 12 <connectionStrings> 13 <add name="Test1" connectionString="Data Source=192.168.1.100;Initial Catalog=Test1;User Id=sa;Password=password01!;" providerName="System.Data.SqlClient"/> 14 <add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-WebApplication1-20140422093630;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-WebApplication1-20140422093630.mdf" /> 15 </connectionStrings> 16 <appSettings> 17 <add key="EnvironAttachment" value="E:\hbwj\hbwj\flfg\"></add> 18 </appSettings> 19 <SubSonicService defaultProvider="Test1"> 20 <providers> 21 22 <add name="Test1" type="SubSonic.SqlDataProvider, SubSonic" connectionStringName="Test1" generatedNamespace="Oceansoft.Net" maxPoolSize="2000"/> 23 24 </providers> 25 </SubSonicService> 26 <system.web> 27 <pages> 28 <controls> 29 <add tagPrefix="webdiyer" assembly="AspNetPager" namespace="Wuqi.Webdiyer"/> 30 <add tagPrefix="oswc" assembly="WebApplication1" namespace="WebApplication1"/> 31 32 </controls> 33 34 </pages> 35 <compilation debug="true" targetFramework="4.0" /> 36 <authentication mode="Forms"> 37 <forms loginUrl="~/Account/Login" timeout="2880" defaultUrl="~/" /> 38 </authentication> 39 <profile defaultProvider="DefaultProfileProvider"> 40 <providers> 41 <add name="DefaultProfileProvider" type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" /> 42 </providers> 43 </profile> 44 <membership defaultProvider="DefaultMembershipProvider"> 45 <providers> 46 <add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" /> 47 </providers> 48 </membership> 49 <roleManager defaultProvider="DefaultRoleProvider"> 50 <providers> 51 <add name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" /> 52 </providers> 53 </roleManager> 54 <!-- 55 If you are deploying to a cloud environment that has multiple web server instances, 56 you should change session state mode from "InProc" to "Custom". In addition, 57 change the connection string named "DefaultConnection" to connect to an instance 58 of SQL Server (including SQL Azure and SQL Compact) instead of to SQL Server Express. 59 --> 60 <sessionState mode="InProc" customProvider="DefaultSessionProvider"> 61 <providers> 62 <add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" /> 63 </providers> 64 </sessionState> 65 </system.web> 66 <system.webServer> 67 <modules runAllManagedModulesForAllRequests="true" /> 68 </system.webServer> 69 <runtime> 70 <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 71 <dependentAssembly> 72 <assemblyIdentity name="DotNetOpenAuth.Core" publicKeyToken="2780ccd10d57b246" /> 73 <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.1.0.0" /> 74 </dependentAssembly> 75 <dependentAssembly> 76 <assemblyIdentity name="DotNetOpenAuth.AspNet" publicKeyToken="2780ccd10d57b246" /> 77 <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.1.0.0" /> 78 </dependentAssembly> 79 </assemblyBinding> 80 </runtime> 81 <entityFramework> 82 <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" /> 83 </entityFramework> 84 </configuration>
BLL 文件下的两个类:PagingEntity,PagingEntity_CusMS
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5
6 namespace Oceansoft.Net.Bll.Common
7 {
8 public class PagingEntity
9 {
10
11
12 /// <summary>
13 /// 页码
14 /// </summary>
15 public int PageIndex { get; set; }
16
17 /// <summary>
18 /// 总记录数
19 /// </summary>
20 public int TotalRecords { get; set; }
21
22 private List<string> _SortExpress = new List<string>();
23
24 /// <summary>
25 /// 排序集合
26 /// </summary>
27 public List<string> SortExpress
28 {
29 get { return this._SortExpress; }
30 set { this._SortExpress = value; }
31 }
32
33
34 private Dictionary<string, string> _filter = new Dictionary<string, string>();
35 /// <summary>
36 /// 条件集合
37 /// </summary>
38 public Dictionary<string, string> Filter
39 {
40 get { return this._filter; }
41 set { this._filter = value; }
42 }
43
44
45 /// <summary>
46 /// 页大小
47 /// </summary>
48 public int PageSize { get; set; }
49
50
51 private List<string> _Paras = new List<string>();
52
53 /// <summary>
54 /// oracle查询参数
55 /// </summary>
56 public List<string> Paras
57 {
58 get { return this._Paras; }
59 set { this._Paras = value; }
60 }
61
62 /// <summary>
63 /// 获取单一值
64 /// </summary>
65 /// <param name="strSql"></param>
66 /// <returns></returns>
67 public virtual object GetSingle(string strSql)
68 {
69 return DB.Query().ExecuteScalar<object>(strSql, Paras.ToArray());
70 }
71
72
73
74 //
75
76
77
78 /// <summary>
79 /// 获取分页sql语句Oracle
80 /// </summary>
81 /// <returns></returns>
82 public string GetPagingSql_Orcle(string sqlText)
83 {
84 int PageIndex = 0;
85 PageIndex = this.PageIndex;
86 // 计算分页大小,和分页数
87 string sqlTextCount = string.Format("select count(1) from ({0}) t", sqlText);
88 this.TotalRecords = Convert.ToInt32(GetSingle(sqlTextCount));
89
90
91
92 string sqlTextRecord = @"select * from (
93 select TT1.*,rownum rn from ({0} {1})
94 TT1 where rownum <={3}) tt2
95 where rn >{2} ";
96 string orderText = "";
97 if (this.SortExpress.Count > 0)
98 {
99 for (int i = 0; i < this.SortExpress.Count; i++)
100 {
101 if (!String.IsNullOrEmpty(this.SortExpress[i]))
102 {
103 if (this.SortExpress[i].ToLower().IndexOf("(none)") == -1)
104 {
105 if (orderText == "")
106 orderText = " order by " + this.SortExpress[i];
107 else
108 orderText += "," + this.SortExpress[i];
109 }
110 }
111 }
112 }
113 //起始页为0
114 //sqlTextRecord = string.Format(sqlTextRecord,
115
116 // sqlText,
117 // orderText,
118 // PageIndex * this.PageSize,
119 // (PageIndex + 1) * this.PageSize
120 // );
121 //起始页为1
122 PageIndex = PageIndex - 1;
123 sqlTextRecord = string.Format(sqlTextRecord,
124
125 sqlText,
126 orderText,
127 PageIndex * this.PageSize,
128 (PageIndex + 1) * this.PageSize
129 );
130 return sqlTextRecord;
131 }
132
133
134
135 /// <summary>
136 /// 获取分页sql语句SQLServer
137 /// </summary>
138 /// <param name="sqlText"></param>
139 /// <returns></returns>
140 public string GetPagingSql_SQLServer(string sqlText)
141 {
142
143 string sqlTextCount = string.Format("select count(1) from ({0}) t", sqlText);
144 TotalRecords = Convert.ToInt32(this.GetSingle(sqlTextCount));
145
146 int PageIndex = 0;
147 PageIndex = this.PageIndex;
148
149 string orderText = "";
150 if (this.SortExpress.Count > 0)
151 {
152 for (int i = 0; i < this.SortExpress.Count; i++)
153 {
154 if (!String.IsNullOrEmpty(this.SortExpress[i]))
155 {
156 if (this.SortExpress[i].ToLower().IndexOf("(none)") == -1)
157 {
158 if (orderText == "")
159 orderText = " " + this.SortExpress[i];
160 else
161 orderText += "," + this.SortExpress[i];
162 }
163 }
164 }
165 }
166 if (string.IsNullOrEmpty(orderText))
167 orderText = "Guid";
168 PageIndex = PageIndex - 1;
169 string sqlTextRecord = string.Format("select * from (select (ROW_NUMBER() OVER(ORDER BY {1})) as rownumber, TT1.* from ({0}) TT1 ) B where rownumber > {2} and rownumber <= {3} order by {1}",
170 sqlText,
171 orderText,
172 PageIndex * PageSize,
173 (PageIndex + 1) * PageSize
174 );
175 return sqlTextRecord;
176 }
177
178 /// <summary>
179 /// 获取sql语句SQLServer(无分页)
180 /// </summary>
181 /// <param name="sqlText"></param>
182 /// <returns></returns>
183 public string GetPagingSql_SQLServerEs(string sqlText)
184 {
185
186 string sqlTextCount = string.Format("select count(1) from ({0}) t", sqlText);
187 TotalRecords = Convert.ToInt32(this.GetSingle(sqlTextCount));
188
189 int PageIndex = 0;
190 PageIndex = this.PageIndex;
191
192 string orderText = "";
193 if (this.SortExpress.Count > 0)
194 {
195 for (int i = 0; i < this.SortExpress.Count; i++)
196 {
197 if (!String.IsNullOrEmpty(this.SortExpress[i]))
198 {
199 if (this.SortExpress[i].ToLower().IndexOf("(none)") == -1)
200 {
201 if (orderText == "")
202 orderText = " " + this.SortExpress[i];
203 else
204 orderText += "," + this.SortExpress[i];
205 }
206 }
207 }
208 }
209 if (string.IsNullOrEmpty(orderText))
210 orderText = "Guid";
211 PageIndex = PageIndex - 1;
212 string sqlTextRecord = string.Format("select * from (select (ROW_NUMBER() OVER(ORDER BY {1})) as rownumber, TT1.* from ({0}) TT1 ) B order by {1}",
213 sqlText,
214 orderText
215 );
216 return sqlTextRecord;
217 }
218
219 }
220 }
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5
6 namespace Oceansoft.Net.Bll.Common
7 {
8 public class PagingEntity_CusMS:PagingEntity
9 {
10 public override object GetSingle(string strSql)
11 {
12 return Oceansoft.Net.DB.Query().ExecuteScalar<object>(strSql, Paras.ToArray());
13 }
14 }
15 }
代码下载: http://files.cnblogs.com/jbps/%E5%88%86%E9%A1%B5%E6%8E%A7%E4%BB%B6AspNetPager.rar
效果图:

来源:https://www.cnblogs.com/jbps/p/3681100.html