使用ASP.NET中继器进行分页?

时间:2010-02-05 12:00:29

标签: c# asp.net vb.net repeater

我正在使用ASP.NET Repeater。

My Repeater名为myRepeater,我只想在每页显示20个项目。

可以使用ASP.NET Repeater完成此操作吗?如果是,我必须对下面的代码进行哪些更改?我希望能够使用分页.......... C#示例也很好!!

 ' Define data objects
    Dim conn As SqlConnection
    Dim Comm As SqlCommand
    Dim reader As SqlDataReader

    conn = New Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)

    Comm = New SqlCommand( _
    ("Select * from TableName"), conn)

    ' Open the connection
    conn.Open()

    ' Execute the category command
    reader = Comm.ExecuteReader()

    ' Bind the reader to the repeater..........
    myRepeater.DataSource = reader
    myRepeater.DataBind()

    ' Close the reader
    reader.Close()
    ' Close the connection
    conn.Close()

提前致谢!!

3 个答案:

答案 0 :(得分:5)

This article可能会帮助你。您将不得不自己创建分页逻辑。我建议使用分页控件,你只需要一个“上一个”和一个“下一个”,你可以根据你在分页数据集中的“where”来启用/禁用这些操作。

答案 1 :(得分:1)

我的博客中有关于此的帖子: http://ozsenegal.wordpress.com/2009/08/16/custom-page-asp-net-com-repeater-e-data-list/

使用谷歌翻译。

答案 2 :(得分:1)

以下是一些可以帮助您入门的指南:

http://www.developer.com/article.php/3646011

http://aspalliance.com/157_Paging_in_DataList

http://www.codeproject.com/KB/webforms/Aspnet_Repeater_Control.aspx

您应该能够将此代码复制并粘贴到项目中,只需更改一些内容以匹配您的项目。