推荐一款.net分页控件——AspNetPager

  一、AspNetPager介绍:  
 
     分页是Web应用程序中最常用到的功能之一,在 ASP.NET中,虽然自带了一个可以分页的DataGrid(asp.net 1.1)和GridView(asp.net 2.0)控件,但其分页功能并不尽如人意,如可定制性差、无法通过Url实现分页功能等,而且有时候我们需要对DataList和Repeater甚至自定义数据绑定控件进行分页,手工编写分页代码不但技术难度大、任务繁琐而且代码重用率极低,因此分页已成为许多ASP.NET程序员最头疼的问题之一。 

     AspNetPager 针对ASP.NET分页控件的不足,提出了与众不同的解决asp.net中分页问题的方案,即将分页导航功能与数据显示功能完全独立开来,由用户自己控制数据的获取及显示方式,因此可以被灵活地应用于任何需要实现分页导航功能的地方,如为GridView、DataList以及Repeater等数据绑定控件实现分页、呈现自定义的分页数据以及制作图片浏览程序等,因为AspNetPager控件和数据是独立的,因此要分页的数据可以来自任何数据源,如 SQL Server、Oracle、Access、mysql、DB2等数据库以及XML文件、内存数据或缓存中的数据、文件系统等等。

      二、AspNetPager的主要功能:

     1、支持通过Url进行分页:
     AspNetPager 除提供默认的类似于DataGrid和GridView的PostBack分页方式外,还支持通过Url进行分页,象大多数asp程序中分页一样, Url分页方式允许用户通过在浏览器地址栏中输入相应的地址即可直接进入指定页面,也可以使搜索引擎搜索到所有分页的页面的内容,因此具有用户友好和搜索引擎友好的优点。

     2、支持Url分页方式下的Url重写(UrlRewrite)功能
     Url 重写技术可以使显示给用户的Url不同于实际的Url,Url重写技术被广泛应用于搜索引擎优化(SEO)、网站重组后重定向页面路径以及提供用户友好的 Url等方面, AspNetPager支持Url重写技术使您可以自定义分页导航的Url格式,实现Url重写;

     3、支持使用用户自定义图片做为导航元素:
     您可以使用自定义的图片文件做为分页控件的导航元素,而不仅仅限于显示文字内容。

     4、功能强大灵活、使用方便、可定制性强:
     AspNetPager 分页控件的所有导航元素都可以由用户进行单独控制,从6.0版起,AspNetPager支持使用主题(Theme)与皮肤(Skin)统一控件的整体样式,配合asp.net 2.0中的DataSource控件,AspNetPager只需要编写短短几行代码,甚至无需编写任何代码,只需设置几个属性就可以实现分页功能。

     5、增强的 Visual Studio 2005/2008设计时支持
     增强的设计时支持使控件在设计时更加直观,易于使用,开发快捷方便。

     6、兼容IE6.0+及FireFox 1.5+等浏览器

     7、丰富而完整的控件文档和示例项目:
     控件附带的完整的帮助文档及示例项目能够帮助您快速上手,熟悉AspNetPager控件的使用,您还可以通过给作者留言以及论坛提问等方式解决控件使用中遇到的问题。 

     三 AspNetPager在线演示

     四、 AspNetPager控件 7.2 版帮助文档

     五、 AspNetPager控件下载

     六、 AspNetPager分页存储过程生成器      
     
     七、使用实例

     1、AspNetPager 7.2 版 For .NET2.0 控件简单分页实例

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="paging.aspx.cs" Inherits="VoteInfo.paging" %>
<%@ Register assembly="AspNetPager" namespace="Wuqi.Webdiyer" tagprefix="webdiyer" %>
<!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="Repeater1" runat="server" >
        
<HeaderTemplate>
        
<table width="100%" border="1" cellspacing="0" cellpadding="4" style="border-collapse:collapse">
        
<tr style="backGround-color:#CCCCFF">
        
<th style="width:15%">姓名</th>
        
<th style="width:15%">性别</th>
        
<th style="width:30%">年龄</th>
        
<th style="width:20%">毕业院校专业</th>
        
<th style="width:20%">学位学历</th></tr>
        
</HeaderTemplate>
        
<ItemTemplate>
        
<tr style="background-color:#FAF3DC">
        
<td><%#DataBinder.Eval(Container.DataItem,"Name")%></td>
        
<td><%#DataBinder.Eval(Container.DataItem, "Sex")%></td>
        
<td><%#DataBinder.Eval(Container.DataItem, "Age")%></td>
        
<td><%#DataBinder.Eval(Container.DataItem, "GraduateUnversity")%></td>
        
<td><%#DataBinder.Eval(Container.DataItem, "Degree")%></td>
        
</tr>
        
</ItemTemplate>
        
<FooterTemplate>
        
</table>
        
</FooterTemplate>
        
</asp:Repeater>
     
<webdiyer:AspNetPager ID="AspNetPager1" runat="server" 
         onpagechanged
="AspNetPager1_PageChanged" 
         CurrentPageButtonPosition
="Center" 
         CustomInfoHTML
="第%CurrentPageIndex%页,共%PageCount%页,每页%PageSize%条" 
         FirstPageText
="首页" LastPageText="尾页" LayoutType="Table" NextPageText="下一页" 
         PageIndexBoxType
="DropDownList" PagingButtonLayoutType="Span" 
         PrevPageText
="上一页" ShowCustomInfoSection="Left" SubmitButtonText="Go" 
         TextAfterPageIndexBox
="页" TextBeforePageIndexBox="转到">
     
</webdiyer:AspNetPager>
    
</form>
</body>
</html>


using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

namespace VoteInfo
{
    
public partial class paging : System.Web.UI.Page
    
{
        
private DataAccess da = new DataAccess();
        
protected void Page_Load(object sender, EventArgs e)
        
{
            
string sql = "select * from CadreInfo";            
            DataTable dt 
= new DataTable();
            dt 
= da.ExecuteDataTable(sql);
            AspNetPager1.RecordCount 
= dt.Rows.Count;
            
this.RPDataBind();
        }


        
private void RPDataBind()
        
{
            
try
            
{
                SqlDataAdapter sda
=new SqlDataAdapter("select * from CadreInfo",da.ConnectString);
                DataSet ds
=new DataSet ();
                AspNetPager1.AlwaysShow 
=true;
                AspNetPager1.PageSize 
=20;
                sda.Fill(ds,AspNetPager1.PageSize 
* (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, "dbTable");
                
this.Repeater1.DataSource =ds.Tables[0];
                
this.Repeater1.DataBind();
            }

            
catch { }
        }

        
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        
{           
            RPDataBind();
        }

    }

}


      2、AspNetPager 控件调用存储过程分页实例

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SP_Paging.aspx.cs" Inherits="FLX.ComplexQuery.SP_Paging" %>

<%@ Register assembly="AspNetPager" namespace="Wuqi.Webdiyer" tagprefix="webdiyer" %>

<!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">
    
<div>
    
    
</div>
    
<asp:GridView ID="GridView1" runat="server">
    
</asp:GridView>
    
<webdiyer:AspNetPager ID="AspNetPager1" runat="server" 
        CustomInfoHTML
="第%CurrentPageIndex%页,共%PageCount%页,每页%PageSize%条" 
        FirstPageText
="首页" LastPageText="尾页" LayoutType="Table" NextPageText="下一页" 
        onpagechanged
="AspNetPager1_PageChanged" PageIndexBoxType="DropDownList" 
        PagingButtonLayoutType
="Span" PrevPageText="上一页" ShowCustomInfoSection="Left" 
        ShowPageIndexBox
="Always" SubmitButtonText="Go" TextAfterPageIndexBox="页" 
        TextBeforePageIndexBox
="转到">
    
</webdiyer:AspNetPager>
    
</form>
</body>
</html>


using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using FLX.ORM;

namespace FLX.ComplexQuery
{
    
public partial class SP_Paging : System.Web.UI.Page
    
{
        
protected void Page_Load(object sender, EventArgs e)
        
{
            
if (!IsPostBack)
            
{
                
this.AspNetPager1.RecordCount = (int)FLX.ORM.BrokerFactory.GetBroker(Config.DataBasePath).DataAccess.ExecuteProcScalar("P_GetCounts");
                
this.GWBind();
            }

        }


        
private void GWBind()
        
{
            ArrayList param 
= new ArrayList();
            param.Add(
new ParamInfo("@startIndex", AspNetPager1.StartRecordIndex));
            param.Add(
new ParamInfo("@endIndex", AspNetPager1.EndRecordIndex));
            GridView1.DataSource 
= FLX.ORM.BrokerFactory.GetBroker(Config.DataBasePath).DataAccess.ExecuteProcDataTable("SP_Paging", param);
            GridView1.DataBind();  
        }


        
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        
{
            
this.GWBind();
        }

    }

}



create PROCEDURE [dbo].[P_GetCounts]
AS
    
select count(GUID) from ConfigDate;
    
RETURN


create  procedure [dbo].[SP_Paging] 
(
@startIndex int,
@endIndex int)
as

begin
 
with temptbl as (
SELECT ROW_NUMBER() OVER (ORDER BY GUID desc)AS Row, * from ConfigDate )
 
SELECT * FROM temptbl where Row between @startIndex and @endIndex
end

      3、AspNetPager 6.0 版 For .NET1.1 控件简单分页实例 

<%@ Page language="c#" Codebehind="ArticleManage.aspx.cs" AutoEventWireup="false" Inherits="ArticleManage._Default" %>
<%@ Register TagPrefix="webdiyer" Namespace="Wuqi.Webdiyer" Assembly="AspNetPager" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
    
<HEAD>
        
<title>文件管理</title>
        
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
        
<meta content="C#" name="CODE_LANGUAGE">
        
<meta content="JavaScript" name="vs_defaultClientScript">
        
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
        
<script>                
            function Pop(url) {
                window.open(url,
"_blank");
            }    
        
</script>
        
<LINK href="CSS/css.css" type="text/css" rel="stylesheet">
        
<style type="text/css">.a { FONT-SIZE: 12px; COLOR: #000000; FONT-FAMILY: 宋体; TEXT-DECORATION: none }
        
</style>
    
</HEAD>
    
<body>
        
<form id="form1" runat="server">
            
<table width="100%" border="0" cellPadding="0" cellSpacing="0" bgcolor="#3bc6dd">
                
<tr>
                    
<td vAlign="top" align="left" width="270" height="110"><IMG height="110" src="images/docc_top_logo.jpg" width="270"></td>
                    
<td vAlign="middle" align="center" bgColor="#3bc6dd">
                        
<table cellSpacing="0" cellPadding="0" width="100%" border="0">
                            
<tr>
                                
<td vAlign="middle" align="left"><asp:label id="LblArticleType" runat="server" CssClass="font4"></asp:label></td>
                            
</tr>
                        
</table>
                    
</td>
                
</tr>
            
</table>
            
<table cellSpacing="0" cellPadding="0" width="98%" align="center" border="0">
                
<tr>
                    
<td>&nbsp;</td>
                
</tr>
            
</table>
            
<table cellSpacing="0" cellPadding="5" width="98%" align="center" border="0">
                
<tr>
                    
<td vAlign="middle" align="left" bgColor="#f0f0f0"><asp:label id="LblName" runat="server" Font-Size="12px" Text="姓名:">搜索:</asp:label>
                        
<asp:TextBox ID="TxtSearchCondtion" runat="server" Width="200px"></asp:TextBox>
                        
<asp:ImageButton id="IBtnQuery" runat="server" ImageUrl="images/js_002.jpg"></asp:ImageButton></td>
                    
<td align="right" valign="middle" bgcolor="#f0f0f0"><a href="Default.aspx" class="font3">返回首页</a></td>
                
</tr>
            
</table>
            
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
                
<tr>
                    
<td height="8"></td>
                
</tr>
            
</table>
            
<TABLE id="Table1" cellSpacing="0" cellPadding="0" width="98%" align="center" border="0">
                
<TR>
                    
<TD>
                        
<TABLE id="Table2" style="FONT-SIZE: 12px" cellSpacing="0" cellPadding="0" width="100%"
                            border
="0">
                            
<tr>
                                
<td colspan="4" align="center">
                                
</td>
                            
</tr>
                            
<TR>
                                
<TD height="40" colSpan="4" valign="middle"><asp:DataGrid ID="dgArticleInfo" Font-Size="12px" runat="server" AutoGenerateColumns="False" BorderColor="#FFFFFF"
                                        BorderStyle
="None" BackColor="#D3D3D3" border="0" CellSpacing="1" CellPadding="5" Width="100%" PageSize="20">
                                        
<FooterStyle ForeColor="#000066" BackColor="White"></FooterStyle>
                                        
<SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="White"></SelectedItemStyle>
                                        
<ItemStyle ForeColor="#000066" BorderColor="Black" CssClass="font1" BackColor="White"></ItemStyle>
                                        
<HeaderStyle ForeColor="Black" CssClass="font2" BackColor="#F0F0F0"></HeaderStyle>
                                        
<Columns>
                                            
<asp:TemplateColumn HeaderText="序号">
                                                
<HeaderStyle HorizontalAlign="Center" Width="30px"></HeaderStyle>
                                                
<ItemStyle HorizontalAlign="Center"></ItemStyle>
                                                
<ItemTemplate>
                                                    
<%# (dgArticleInfo.PageSize * dgArticleInfo.CurrentPageIndex) + Container.ItemIndex +1 %>
                                                
</ItemTemplate>
                                            
</asp:TemplateColumn>
                                            
<asp:TemplateColumn HeaderText="文件标题">
                                                
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
                                                
<ItemTemplate>
                                                    
<a href='#' class="font3" onClick='Pop("ViewArticle.aspx?ArticleID=<%#DataBinder.Eval(Container.DataItem,"ArticleID")%>");'>
                                                        
<%#DataBinder.Eval(Container.DataItem,"Title")%>
                                                    
</a>
                                                
</ItemTemplate>
                                            
</asp:TemplateColumn>
                                            
<asp:TemplateColumn HeaderText="文号">
                                                
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
                                                
<ItemStyle Width="120px"></ItemStyle>
                                                
<ItemTemplate>
                                                    
<%#DataBinder.Eval(Container.DataItem,"ArticleWH")%>
                                                
</ItemTemplate>
                                            
</asp:TemplateColumn>
                                            
<asp:BoundColumn DataField="DispatchUnit" HeaderText="发文单位">
                                                
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
                                                
<ItemStyle Width="200px"></ItemStyle>
                                            
</asp:BoundColumn>
                                            
<asp:BoundColumn DataField="PublishDT" HeaderText="颁布日期" DataFormatString="{0:d}">
                                                
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
                                                
<ItemStyle Width="60px"></ItemStyle>
                                            
</asp:BoundColumn>
                                        
</Columns>
                                        
<PagerStyle NextPageText="下一页" PrevPageText="上一页" HorizontalAlign="Center" ForeColor="#000066"
                                            BackColor
="White" PageButtonCount="30" Mode="NumericPages"></PagerStyle>
                                    
</asp:DataGrid></TD>
                            
</TR>
                            
<tr>
                                
<td colSpan="4" align="center"><webdiyer:AspNetPager ID="AspNetPager1" runat="server" CurrentPageButtonPosition="Center" CustomInfoHTML="共%PageCount%页 %RecordCount%篇文档 每页%PageSize%篇"
                                        FirstPageText
="首页" LastPageText="尾页" LayoutType="Table" NextPageText="下一页" PageIndexBoxType="DropDownList" PagingButtonLayoutType="Span"
                                        PrevPageText
="上一页" ShowCustomInfoSection="Left" SubmitButtonText="跳转" TextAfterPageIndexBox="" TextBeforePageIndexBox="转到" PageSize="20"
                                        AlwaysShow
="True" Font-Size="Small" ShowInputBox="Always" CustomInfoTextAlign="Center" CssClass="font6" CustomInfoClass="font5"
                                        TextBeforeInputBox
="跳转到第" TextAfterInputBox=""></webdiyer:AspNetPager>
                                
</td>
                            
</tr>
                        
</TABLE>
                    
</TD>
                
</TR>
            
</TABLE>
        
</form>
    
</body>
</HTML>


using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace ArticleManage
{
    
/// <summary>
    
/// _Default 的摘要说明。
    
/// </summary>
    public class _Default : System.Web.UI.Page
    {
        
protected System.Web.UI.WebControls.Label LblName;
        
protected System.Web.UI.WebControls.DataGrid dgArticleInfo;
        
protected System.Web.UI.WebControls.TextBox TxtSearchCondtion;
        
protected System.Web.UI.WebControls.Label LblArticleType;
        
protected System.Web.UI.WebControls.ImageButton IBtnQuery;
        
protected Wuqi.Webdiyer.AspNetPager AspNetPager1;
        
private DataAccess da=new DataAccess();
        
private void Page_Load(object sender, System.EventArgs e)
        {
            
// 在此处放置用户代码以初始化页面
            if (!IsPostBack)
            {
                
this.GetPageRecord();
                
this.dgDataBind();
            }
        }

        
#region Web 窗体设计器生成的代码
        
override protected void OnInit(EventArgs e)
        {
            
//
            
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
            
//
            InitializeComponent();
            
base.OnInit(e);
        }
        
        
/// <summary>
        
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
        
/// 此方法的内容。
        
/// </summary>
        private void InitializeComponent()
        {    
            
this.IBtnQuery.Click += new System.Web.UI.ImageClickEventHandler(this.IBtnQuery_Click);
            
this.AspNetPager1.PageChanged += new System.EventHandler(this.AspNetPager1_PageChanged);
            
this.Load += new System.EventHandler(this.Page_Load);

        }
        
#endregion

        
private string QuerySql()
        {
            
string strtype=Request["Type"];
            
string strflag=Request["flag"];
            
string sql = "select * from ArticleManage where 1=1";
            
if(strflag=="1" && strtype!="" && strtype!=null)
            {            
                sql
+=" and yearnum='["+strtype.Replace("","")+"]'";
                
this.LblArticleType.Text =strtype+"人事人才政策法规";
            }
            
if(strflag=="2" && strtype!="" && strtype!=null)
            {            
                sql
+=" and ClassName='"+strtype+"'";
                
this.LblArticleType.Text =strtype+"人事人才政策法规";
            }
            
if (this.TxtSearchCondtion.Text.Trim() != "")
            {
                
string SearchCondtion=this.TxtSearchCondtion.Text.Replace("[","").Replace("]","").Replace("'","").ToString();
                sql 
+=" and (SubjectWord like '%"+ SearchCondtion+"%' Or Related like '%"+ SearchCondtion+"%' Or QueryArticleWH like '%"+ SearchCondtion+"%' Or dispatchunit like '%"+ SearchCondtion+"%' Or Title like '%"+ SearchCondtion+"%' Or Content like '%"+ SearchCondtion+"%')";
            }
            sql
+=" Order by PublishDT Desc";
            
return sql;
        }

        
private void dgDataBind()
        {
            
try
            {
                
string sql = this.QuerySql();
                OleDbDataAdapter sda
=new OleDbDataAdapter(sql,da.ConnectString);
                DataSet ds
=new DataSet();
                sda.Fill(ds,AspNetPager1.PageSize 
* (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, "dbTable");
                
this.dgArticleInfo.DataSource =ds.Tables[0];
                
this.dgArticleInfo.DataBind();
            }
            
catch  {}
        }

        
public void GetPageRecord()
        {
            
string sql=this.QuerySql();
            DataTable dt 
= new DataTable();
            dt 
= da.ExecuteDataTable(sql);                
            
this.AspNetPager1.RecordCount =dt.Rows.Count;
        }

        
private void IBtnQuery_Click(object sender, System.Web.UI.ImageClickEventArgs e)
        {
            
this.GetPageRecord();
            
this.dgDataBind(); 
        }

        
private void AspNetPager1_PageChanged(object sender, System.EventArgs e)
        {
            
this.dgDataBind();
        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值