linq 查询分页实例
2010-11-14 08:09:24 来源:WEB开发网核心提示:后台代码如下(有两个分页方法,一个复杂带跳转,linq 查询分页实例(2),一个简单),当然这两个方法可以放在一个类中任何页面都可以调用using System;using System.Collections.Generic;using System.Linq;using System.Web;using Syste
后台代码如下(有两个分页方法,一个复杂带跳转,一个简单),当然这两个方法可以放在一个类中任何页面都可以调用
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class PageBreakTest : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } //分页器 PageBreak(每页显示条数,第几页,总记录数,显示页面地址,参数) public static string PageBreak(ref int Record, ref int PageNum, int RecordMax, string ActionURL, string Hidden) { int PageTemp, i, MaxPage; System.Text.StringBuilder tmpPageBreak = new System.Text.StringBuilder(); if (Record > RecordMax) { Record = RecordMax; } if (Record < 1) { Record = 1; } MaxPage = RecordMax / Record; if (RecordMax % Record > 0) { MaxPage = MaxPage + 1; } if (PageNum > MaxPage) PageNum = MaxPage; if (PageNum < 1) PageNum = 1; tmpPageBreak.AppendFormat("<form method=\"get\" action=\"{0}\">", ActionURL); tmpPageBreak.Append(Hidden); tmpPageBreak.Append("<div style=\"float: left;width:26%;padding: 10px 0px 0px 0px;text-align : center;\">"); PageTemp = 1; if (MaxPage > 1) { if (PageNum > 1) { tmpPageBreak.Append("<a href=\"#\" onclick=\"JScript:this.parentNode.parentNode.PageNum.value='1';this.parentNode.parentNode.submit();return false;\">首页</a> "); tmpPageBreak.AppendFormat("<a href=\"#\" onclick=\"JScript:this.parentNode.parentNode.PageNum.value='{0}';this.parentNode.parentNode.submit();return false;\">前页</a>", PageNum - 1); } else { tmpPageBreak.Append("首页 前页"); } if (PageNum < MaxPage) { tmpPageBreak.AppendFormat(" <a href=\"#\" onclick=\"JScript:this.parentNode.parentNode.PageNum.value='{0}';this.parentNode.parentNode.submit();return false;\">后页</a> ", PageNum + 1); tmpPageBreak.AppendFormat("<a href=\"#\" onclick=\"JScript:this.parentNode.parentNode.PageNum.value='{0}';this.parentNode.parentNode.submit();return false;\">尾页</a>", MaxPage); PageTemp = PageNum + 1; } else { tmpPageBreak.AppendFormat(" 后页 尾页"); } } else { tmpPageBreak.AppendFormat("首页 前页 后页 尾页"); } tmpPageBreak.AppendFormat("</div>"); tmpPageBreak.AppendFormat("<div style=\"float: right;width:30%;text-align : center;\">转到:<select name=\"PageNum\">"); for (i = 1; i <= MaxPage; i++) { tmpPageBreak.AppendFormat("<option value=\"{0}\"", i); if (i == PageTemp) { tmpPageBreak.Append(" selected=\"selected\""); } tmpPageBreak.AppendFormat(">{0}</option>", i); } tmpPageBreak.AppendFormat("</select> <button onclick=\"JScript:this.form.submit();\"><img border=\"0\" src=\"{0}/Images/Goto.Gif\" align=\"absbottom\" /> 翻页</button>", ""); tmpPageBreak.Append("</div>"); tmpPageBreak.Append("<div style=\"padding: 3px 0px 0px 0px;text-align : center;\">"); tmpPageBreak.AppendFormat("共{0}条信息 每页<input maxlength=\"4\" class=\"MyText\" valueType=\"integer\" type=\"text\" name=\"Record\" size=\"2\" value=\"{1}\" />条 页次:<span style=\"font-weight:bold;color:red\">{2}</span>/{3}页", RecordMax, Record, PageNum, MaxPage); tmpPageBreak.Append("</div></form>"); return tmpPageBreak.ToString(); } public static string PageBreak2(ref int Record, ref int PageNum, int RecordMax, string ActionURL, string Hidden) { int PageTemp, i, MaxPage; System.Text.StringBuilder tmpPageBreak = new System.Text.StringBuilder(); if (Record > RecordMax) { Record = RecordMax; } if (Record < 1) { Record = 1; } MaxPage = RecordMax / Record; if (RecordMax % Record > 0) { MaxPage = MaxPage + 1; } if (PageNum > MaxPage) PageNum = MaxPage; if (PageNum < 1) PageNum = 1; tmpPageBreak.AppendFormat("<form method=\"get\" action=\"{0}\">", ActionURL); tmpPageBreak.Append(Hidden); tmpPageBreak.Append("<div style=\"float: left;width:26%;padding: 10px 0px 0px 0px;text-align : center;\">"); PageTemp = 1; if (MaxPage > 1) { if (PageNum > 1) { tmpPageBreak.Append("<a href=\"#\" onclick=\"JScript:this.parentNode.parentNode.PageNum.value='1';this.parentNode.parentNode.submit();return false;\">首页</a> "); tmpPageBreak.AppendFormat("<a href=\"#\" onclick=\"JScript:this.parentNode.parentNode.PageNum.value='{0}';this.parentNode.parentNode.submit();return false;\">前页</a>", PageNum - 1); } else { tmpPageBreak.Append("首页 前页"); } if (PageNum < MaxPage) { tmpPageBreak.AppendFormat(" <a href=\"#\" onclick=\"JScript:this.parentNode.parentNode.PageNum.value='{0}';this.parentNode.parentNode.submit();return false;\">后页</a> ", PageNum + 1); tmpPageBreak.AppendFormat("<a href=\"#\" onclick=\"JScript:this.parentNode.parentNode.PageNum.value='{0}';this.parentNode.parentNode.submit();return false;\">尾页</a>", MaxPage); PageTemp = PageNum + 1; } else { tmpPageBreak.AppendFormat(" 后页 尾页"); } } else { tmpPageBreak.AppendFormat("首页 前页 后页 尾页"); } tmpPageBreak.AppendFormat("</div>"); tmpPageBreak.AppendFormat("<div style=\"float: right;width:30%;text-align: center;display:none;\">转到:<select name=\"PageNum\">"); for (i = 1; i <= MaxPage; i++) { tmpPageBreak.AppendFormat("<option value=\"{0}\"", i); if (i == PageTemp) { tmpPageBreak.Append(" selected=\"selected\""); } tmpPageBreak.AppendFormat(">{0}</option>", i); } tmpPageBreak.AppendFormat("</select> <button onclick=\"JScript:this.form.submit();\"><img border=\"0\" src=\"{0}/Images/Goto.Gif\" align=\"absbottom\" /> 翻页</button>", ""); tmpPageBreak.Append("</div>"); tmpPageBreak.Append("<div style=\"padding: 3px 0px 0px 0px;text-align : center;\">"); tmpPageBreak.AppendFormat("共{0}条信息 每页{1}条 页次:<span style=\"font-weight:bold;color:red\">{2}</span>/{3}页", RecordMax, Record, PageNum, MaxPage); tmpPageBreak.Append("</div></form>"); return tmpPageBreak.ToString(); } }
更多精彩
赞助商链接