您的位置:首页 > 编程语言 > ASP

ASP.NET2.0 分页控件 PagerPro.dll (1.1.0 最新)

2007-08-14 21:24 453 查看
快来瞧,快来看了啊,新出炉的ASP.NET分页控件,热乎啦!

最新的ASP.NET2.0分页控件,经过对样式的处理,现有None和Standard两种样式,可以自定义是否显示Page Count 和 Goto page button 用起来极为方便,专为懒人打造。用法与通用分页控件相似,只需给定一个参数RecordCount即可。

Sytle “None”



Sytle “Standard”



使用步骤:

一、下载 ASP.NET2.0分页控件PagerPro.dll (废话),在项目中添加引用。

二、提供两个public 方法,分别来获取数据源(Datasource)及返回的记录总数(RecordCount)

例:本例使用的数据库为NorthWind 表为Customers

1 using System;

2 using System.Collections.Generic;

3 using System.Text;

4 using System.Data;

5 using System.Data.OleDb;

6

7 namespace DLL

8 {

9 public class PagerDB

10 {

11 public static string strCon = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\Database\NorthWind.mdb;";

12 private static OleDbConnection conn;

13

14 public static DataView GetCustomers(int pageIndex, int pageSize)

15 {

16 string strCmd="";

17 int topNum = (pageIndex - 1) * pageSize;

18 if (topNum == 0)

19 strCmd = "select top " + pageSize + " * from Customers order by CustomerID";

20 else

21 strCmd = "select top " + pageSize + " * from Customers where CustomerID not in (select top " + topNum + " CustomerID from Customers order by CustomerID) order by CustomerID";

22 conn = new OleDbConnection(strCon);

23 conn.Open();

24 OleDbDataAdapter da = new OleDbDataAdapter(strCmd,conn);

25 DataSet ds = new DataSet();

26 da.Fill(ds,"Customers");

27 conn.Close();

28 return ds.Tables["Customers"].DefaultView;

29 }

30

31 public static int GetRecordCount()

32 {

33 string strCmd = "select count(CustomerID) from Customers";

34 conn = new OleDbConnection(strCon);

35 conn.Open();

36 OleDbCommand cmd = new OleDbCommand(strCmd, conn);

37 int rows = Convert.ToInt32(cmd.ExecuteScalar());

38 conn.Close();

39 return rows;

40 }

41 }

42 }

三、可以引用分页控件PagerPro.dll, 拖动到页面 或者直接添加注册控件代码。然后添加一个ObjectDataSource数据源控件,并设置其SelectMethod及OnObjectCreating 。 具体设置如下:

1 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

2

3 <%@ Register Assembly="PagerPro" Namespace="Syringa.PagerPro" TagPrefix="Syringa" %>

4 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

5 <html xmlns="http://www.w3.org/1999/xhtml">

6 <head runat="server">

7 <title>Untitled Page</title>

8 </head>

9 <body>

10 <form id="form1" runat="server">

11 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Width="564px"

12 DataSourceID="ObjectDataSource1">

13 <Columns>

14 <asp:BoundField DataField="CustomerID" HeaderText="CustomerID" />

15 <asp:BoundField DataField="CompanyName" HeaderText="CompanyName" />

16 </Columns>

17 </asp:GridView>

18 <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" TypeName="DLL.PagerDB"

19 SelectMethod="GetCustomers" MaximumRowsParameterName="pageSize" StartRowIndexParameterName="pageIndex"

20 OnObjectCreating="ObjectDataSource1_ObjectCreating1">

21 <SelectParameters>

22 <asp:ControlParameter ControlID="PagerPro1" Name="pageIndex" PropertyName="PageIndex"

23 Type="Int32" />

24 <asp:ControlParameter ControlID="PagerPro1" Name="pageSize" PropertyName="PageSize"

25 Type="Int32" />

26 </SelectParameters>

27 </asp:ObjectDataSource>

28 <Syringa:PagerPro ID="PagerPro1" runat="server" DefineStyle="None" PageSize="10" />

29 </form>

30 </body>

31 </html>

32
说明:

1、注册组件<%@ Register Assembly="PagerPro" Namespace="Syringa.PagerPro" TagPrefix="Syringa" %>

2、指定GridView的数据源 DataSourceID="ObjectDataSource1"

3、指定类TypeName="DLL.PagerDB"

4、指定SelectMethod="GetCustomers" MaximumRowsParameterName="pageSize" StartRowIndexParameterName="pageIndex"

5、指定参数来源<asp:ControlParameter ControlID="PagerPro1" Name="pageIndex" PropertyName="PageIndex" Type="Int32" />

<asp:ControlParameter ControlID="PagerPro1" Name="pageSize" PropertyName="PageSize" Type="Int32" />

6、指定事件OnObjectCreating="ObjectDataSource1_ObjectCreating1"

7、分页控件<Syringa:PagerPro ID="PagerPro1" runat="server" DefineStyle="None" PageSize="10" />

四、在OnObjectCreating事件中指定分页控件的RecordCount属性值

1 using System;

2 using System.Data;

3 using System.Configuration;

4 using System.Web;

5 using System.Web.Security;

6 using System.Web.UI;

7 using System.Web.UI.WebControls;

8 using System.Web.UI.WebControls.WebParts;

9 using System.Web.UI.HtmlControls;

10 using Syringa.PagerPro;

11 using DLL;

12

13 public partial class _Default : System.Web.UI.Page

14 {

15 protected void Page_Load(object sender, EventArgs e)

16 {

17 }

18

19 protected void ObjectDataSource1_ObjectCreating1(object sender, ObjectDataSourceEventArgs e)

20 {

21 PagerPro1.RecordCount = PagerDB.GetRecordCount();

22 }

23 }

24

O了,在页面中利用ObjectDataSource简单配置一下,cs中只需一行代码就可以搞定。以下是分页控件的属性及实例的结果。



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: