介绍asp.net的几种分页方式


当前第2页 返回上一页

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using JXSoft.TicketManage.Model;

using JXSoft.TicketManage.BLL;

using System.Text.RegularExpressions;

using System.Data;

namespace JXSoft.TicketManage.Web

{

public partial class Test : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

if(!IsPostBack)

{

BindData();

}

}

protected void BindData()

{

DataTable dt=new DataTable();

dt.Columns.Add("ID");

dt.Columns.Add("Name");

for (int i = 0; i < 10;i++ )

{

dt.Rows.Add(i.ToString(), i.ToString());

}

DataSet ds = new DataSet();

ds.Tables.Add(dt);

Pager(this.GridView1, this.AspNetPager1, ds);

}

protected void Pager(GridView dl, Wuqi.Webdiyer.AspNetPager anp, System.Data.DataSet dst)

{

PagedDataSource pds = new PagedDataSource();

pds.DataSource = dst.Tables[0].DefaultView;

pds.AllowPaging = true;

anp.RecordCount = dst.Tables[0].DefaultView.Count;

pds.CurrentPageIndex = anp.CurrentPageIndex - 1;

pds.PageSize = anp.PageSize;

dl.DataSource = pds;

dl.DataBind();

}

protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)

{

AspNetPager1.CurrentPageIndex = e.NewPageIndex;

BindData();

}

}

}

第三种:使用AspNetPager结合存储过程进行分页
这种方法分页稍微复杂一些,但是可以应付比较大的数据量。
前台:

1

2

3

4

5

6

7

8

9

10

<asp:GridView ID="GridView1" runat="server" CssClass="GridTable" AutoGenerateColumns="false" onrowdatabound="GridView1_RowDataBound" >

</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" PageSize="4" TextAfterPageIndexBox="页"

TextBeforePageIndexBox="转到">

</webdiyer:AspNetPager>

后台:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

//绑定方法中需要传递aspnetpager的两个属性

protected void DataBind(){

DataSet ds = reportQueryBLL.GetTcikDetailReport(this.txtStartDate.Text,this.txtEndDate.Text,int.Parse( this.DropDownListPartment1.SelectedValue),

this.txtPayPerson1.Text,this.txtTicketNum.Text,this.txtTicketNo.Text,

AspNetPager1.StartRecordIndex,AspNetPager1.EndRecordIndex);//注意最后两个参数是aspnetpager的属性。

this.GridView1.DataSource = ds;

this.GridView1.DataBind();

}

//分页控件的页索引变化事件

protected void AspNetPager1_PageChanged(object src, EventArgs e)

{

BindDetailReportToGv();

}

//page_base中需要加载首次的数据条数

DataSet ds = reportQueryBLL.GetDetail(this.txtStartDate.Text, this.txtEndDate.Text, int.Parse(this.DropDownListPartment1.SelectedValue), this.txtPayPerson1.Text, this.txtTicketNum.Text, this.txtTicketNo.Text);

this.AspNetPager1.RecordCount = ds.Tables[0].Rows.Count;

BindDetailReportToGv();

这里用的存储过程比较复杂,因为SQL语句没有能够放到视图中,也无法直接从表中查出结果,这个存储过程有点变态,如果有朋友看到了,希望能指点一下。
其实存储过程的核心在于:

1

2

3

4

5

6

7

8

9

Create PROCEDURE [dbo].[P_GetPagedOrders2005]

(@startIndex INT,

@endindex INT

)

AS

select * from (SELECT ROW_NUMBER() OVER(ORDER BY IPid DESC) AS rownum,

[IPid],[IPFrom],[IPTo],[IPLocation],[IPCity],[IPToNumber],[IPFromNumber] from IPInfo) as U

WHERE rownum between @startIndex and @endIndex

GO

以上就是介绍asp.net的几种分页方式的详细内容!

返回前面的内容

相关阅读 >>

asp.net mvc如何正确运用异步编程技术

asp.net core中间件设置教程(7)_实用技巧

asp.net利用ashx实现验证码功能详解

asp.net操作日期常用代码

实例介绍asp.net项目开发中枚举的使用

解析asp.net如何使用session

c#中list的用法

关于asp.net如何获取浏览器访问的ip地址?

asp.net mvc 5改进了基于过滤器的身份验证

分享两种asp.net网站发布时的遇到的问题及解决方案

更多相关阅读请进入《asp.net》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...