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


本文摘自PHP中文网,作者伊谢尔伦,侵删。

通常分页有3种方法,分别是asp.net自带的数据显示空间如GridView等自带的分页,第三方分页控件如aspnetpager,存储过程分页等。这里分别做总结。
第一种:使用GridView自带分页,这种是最简单的分页方法。
前台的方法

1

2

3

<asp:GridView ID="GridView1" AllowPaging="true" runat="server"

onpageindexchanging="GridView1_PageIndexChanging" PageSize="3">

</asp:GridView>

后台方法:

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

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());

}

this.GridView1.DataSource = dt;

this.GridView1.DataBind();

}

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)

{

this.GridView1.PageIndex = e.NewPageIndex;

BindData();

}

}

}

第二种:使用个性化显示的AspNetPager.dll进行分页
此处需要添加aspnetpager.dll的引用
前台:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

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

<div>

<asp:GridView ID="GridView1" runat="server" >

</asp:GridView>

<webdiyer:AspNetPager ID="AspNetPager1" runat="server"

CustomInfoHTML="第%CurrentPageIndex%页,共%PageCount%页,每页%PageSize%条"

FirstPageText="首页" LastPageText="尾页" LayoutType="Table" NextPageText="下一页"

onpagechanging="AspNetPager1_PageChanging" PageIndexBoxType="DropDownList"

PagingButtonLayoutType="Span" PrevPageText="上一页" ShowCustomInfoSection="Left"

ShowPageIndexBox="Always" SubmitButtonText="Go" PageSize="4" TextAfterPageIndexBox="页"

TextBeforePageIndexBox="转到">

</webdiyer:AspNetPager>

</div>

</form>

后台:

阅读剩余部分

相关阅读 >>

使用action的模型绑定实例教程

asp.net mvc 遇到json循环调用的问题应该怎么解决?

asp.net core中的多语言支持的图文详解

有关asp.net中config文件的读写讲解

.net通过母版实现页脚效果代码实例

asp.net core实例教程之配置

分享asp.net core在开发环境中保存机密(user secrets)的实例

asp.net mvc 使用bootstrap方法介绍

asp.net部署到iis常见问题的解决方法_实用技巧

asp.net通过remoting service上传文件的实例详解

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




打赏

取消

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

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

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

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

评论

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