如何使用AspNetPager控件

如何使用AspNetPager控件,第1张

前台:

<webdiyer:AspNetPager SubmitButtonClass="buttons" ID="AspNetPager1" runat="server" AlwaysShow="True" FirstPageText="首页"

NextPageText="下一页" PrevPageText="前一页" LastPageText="尾页" PageSize="15" ShowInputBox="Always"

OnPageChanged="AspNetPager1_PageChanged">

</webdiyer:AspNetPager>

<!-- PageSize="15"定义每页显示数据条数 -->

后台:

/// <summary>

/// 加载事件

/// </summary>

protected void Page_Load(object sender, EventArgs e)

{

BoundList()

}

/// <summary>

/// 全局的变量,分页用的参数数据信息总数

/// </summary>

public static int sumcount

/// <summary>

/// 绑定信息数据

/// </summary>

private void BoundList()

{

DataTable dt = GetList().Tables[0]//获取数据源

if (dt.Rows.Count >0)

{

sumcount = dt.Rows.Count

PagedDataSource pds = new PagedDataSource()

AspNetPager1.RecordCount = sumcount

pds.AllowPaging = true

pds.PageSize = AspNetPager1.PageSize

pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1

pds.DataSource = dt.DefaultView

this.gridView1.DataSource = pds//可以绑定到Gridview 、datalist等数据控件上,此处为Gridview

this.gridView1.DataBind()

}

else

{

AspNetPager1.RecordCount = 0

this.gridView1.DataSource = null

gridView1.EmptyDataText = "没有相关信息!"

this.gridView1.DataBind()

}

}

/// <summary>

/// 分页控件的翻页事件

/// </summary>

protected void AspNetPager1_PageChanged(object sender, EventArgs e)

{

BoundList()

}

http://zhidao.baidu.com/question/334985338.html?oldq=1

首先添加 AspNetPager.dll 引用,然后编译一下,在工具箱里添加一个选项卡,然后在该选项卡里右键,选择选择项,浏览添加 AspNetPager.dll  就行了 ,望采纳

AspNetPager简单使用方法 AspNetPager作为分页工具,常常用于绑定数据控件,如DataGrid , Repeater等

在这里,简单讲解下 绑定 Repeater 控件的方法,其余控件绑定方法类似:

'全局变量 i 用于 读取 数据集记录的条数(注意:读取一次就够了)

Dim i As New Integer

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

If i = 0 Then

con = New SqlConnection(ConfigurationManager.ConnectionStrings("NEWS_ConnectionString").ConnectionString)

con.Open()

cmd = New SqlCommand()

cmd.Connection = con

cmd.CommandText = "select count(*) from XWNRB "

'AspNetPager控件 可见

Me.AspNetPager1.Visible = True

'AspNetPager控件 每页显示大小为10条记录

Me.AspNetPager1.PageSize = 10

'AspNetPager控件 记录总的记录条数

Me.AspNetPager1.RecordCount = Convert.ToInt32(cmd.ExecuteScalar())

'AspNetPager控件 数据绑定

Me.SHOW_DATA_LIST()

i = i + 1

con.Close()

End If

End Sub

Protected Sub SHOW_DATA_LIST()

con = New SqlConnection(ConfigurationManager.ConnectionStrings("NEWS_ConnectionString").ConnectionString)

sql_Text = "select * from XWNRB where "

da = New SqlDataAdapter(sql_Text, con)

Dim ds As New Data.DataSet

'第一个参数为存储入的数据集为ds

'第二个参数为存储的起始记录序号

'第三个参数为存储的记录每页条数

'第四个参数为存储入的数据集ds中的具体某个表

da.Fill(ds, Me.AspNetPager1.PageSize * (Me.AspNetPager1.CurrentPageIndex - 1), Me.AspNetPager1.PageSize, "NEWS_LIST")

'真正绑定

Me.Repeater2.DataSource = ds.Tables("NEWS_LIST").DefaultView

Me.Repeater2.DataBind()

End Sub

'即每次点击新的页面,或者点击 Pre,Next,Last.....时候都会触发这个事件

Protected Sub AspNetPager1_PageChanged(ByVal src As Object, ByVal e As Wuqi.Webdiyer.PageChangedEventArgs) Handles AspNetPager1.PageChanged

'更新当前所在的页数序列

Me.AspNetPager1.CurrentPageIndex = e.NewPageIndex

'更新完后绑定

Me.SHOW_DATA_LIST()

End Sub


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/bake/11436279.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-16
下一篇2023-05-16

发表评论

登录后才能评论

评论列表(0条)

    保存