浅析ASP.NET高效分页的实现过程(2)
需要补充的是分页排序时id问题: 如果你的SQL语句写成了这样: 1、 select * from table where ... order ... 则优化后的sql以id排序 2、 select *|CustomerId from table where ... order ... 则优化后的sql以Cust
需要补充的是分页排序时id问题:
如果你的SQL语句写成了这样:
- 1、select * from table where ... order ...
- 则优化后的sql以id排序
- 2、select *|CustomerId from table where ... order ...
- 则优化后的sql以CustomerId排序
- 2、select CustomerId,CustomerName,... from table where ... order ...
- 则优化后的sql以CustomerId排序
- ==================================
然后根据当前信息格式化分页显示的htmls,例如,页数、页号、总记录数、以及上下页按钮是否可用。具体代码:
- Code
- public static string AnalyticsPagingHtmls(string tableAndindex,int count, int size, int index)
- {
- string _GetPageHtml = GetPageHtml();
- return string.Format
- (
- _GetPageHtml.Substring(0, _GetPageHtml.IndexOf(",{4}];") + 6),
- count == 0 || count <= size ? "none" : "",
- index == 0 ? "0" : "1",
- index == 0 ? "0" : "1",
- (index + 1 == ((count % size) == 0 ? count / size : ((count / size) + 1))) ? "0" : "1",
- (index + 1 == ((count % size) == 0 ? count / size : ((count / size) + 1))) ? "0" : "1",
- size,
- index + 1,
- (count % size) == 0 ? count / size : (count / size) + 1,
- count,
- count == 0 ? "none" : "",
- tableAndindex,
- ((count % size) == 0 ? count / size : ((count / size) + 1))-1
- )
- + _GetPageHtml.Substring(_GetPageHtml.IndexOf(",{4}];") + 6);
- }
如何使用这个分页方法:
第一步:在配置文件里写下如下代码:
- Code
- <configSections>
- <section name="MyPaging" type="System.Configuration.NameValueSectionHandler"/>
- </configSections>
- <MyPaging>
- <add key="Paging" value="~/Paging/template.htm"/>
- </MyPaging>
第二步:在cs文件里,直接调用就行
- protected void Page_Load(object sender, EventArgs e)
- {
- if(MyPaging.IsPaging)
- {
- p1.InnerHtml = MyPaging.ExecutePaging(MyRep, "select CustomerId,ShipName,ShipAddress,ShippedDate from orders ", 0,5);
- p2.InnerHtml = MyPaging.ExecutePaging(MyRep2, "select CustomerID,CompanyName,ContactName,Address from dbo.Customers", 0,5);
- }
- }
前台代码:
- Code
- <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title></title>
- </head>
- <body>
- <form id="form1" runat="server">
- <asp:Repeater ID="MyRep" runat=server>
- <ItemTemplate>
- <div style="width:100%; height:20px;">
- <%# Eval("CustomerID") %>
- <%# Eval("ShipName") %>
- <%# Eval("ShipAddress") %>
- <%# Eval("ShippedDate")%>
- </div>
- </ItemTemplate>
- </asp:Repeater>
- <div id="p1" runat=server></div>
- <asp:Repeater ID="MyRep2" runat=server>
- <ItemTemplate>
- <div style="width:100%; height:20px;">
- <%# Eval("CustomerID")%>
- <%# Eval("CompanyName")%>
- <%# Eval("ContactName")%>
- <%# Eval("Address")%>
- </div>
- </ItemTemplate>
- </asp:Repeater>
- <div id="p2" runat=server></div>
- </form>
- </body>
- </html>
实现效果:
顶一下
(0)
0%
踩一下
(1)
100%
- 最新评论 查看所有评论
-
- 发表评论 查看所有评论
-
- GRIDVIEW排序 动态实现和静态实现
- ASP.NET2.0数据操作之创建数据访问层
- 单点登录的实现
- ASP.NET程序中常用代码汇总
- ASP.NET中实时图表的实现
- ASP.NET中利用Crystal Report创建图表
- ASP.NET 2.0中Gridview控件高级技巧
- VB中String的用法及原理
- ASP.NET 2.0轻松实现数据库应用开发
- ASP.NET AJAX入门系列(1):概述
- HijackThis使用详解
- 网友整理 .net 面试题(附答案)
- Visual Studio 2005中编译调试
- ASP.NET AJAX入门系列(2):使用ScriptManager控
- ASP.NET2.0中Gridview中数据操作技巧
2012 cheap ugg ugg uggs uggs ugg ugg uggs ugg ugg ugg uggs boots ugg ugg UGGS boots uggs boots. tory burch shoes tory burch outlet for sale.
- C#实现前台与后台方法互调
- ASP.NET下拉框呈现不同颜色的实现
- 为ASP.NET MVC开发一些常用插件(二)—— 实现无
- ASP.NET中URL Rewrite的实现方法
- .NET程序开发在c#中实现3层架构
- .Net 加密原理,虚拟机预处理层加密壳核心的实现
- 利用APSX页面作为模版文件的实现
- ASP.NET多频道网站架构实现方法
- 代码实现DataList控件的分页显示
- 利用ASP.NET AJAX实现表格更新程序
- 如何实现站点的RSS输出
- 如何在Asp.net中实现多彩下拉框
- 利用AJAX和ASP.NET实现简单聊天室
- asp.net利用RAR实现文件压缩解压缩
- 使用ASP.NET AJAX实现幻灯片效果
