Repeater控制分页错误

时间:2012-12-21 20:24:24

标签: asp.net vb.net

我正在尝试在转发器控件中创建一个寻呼机。内容正从数据库中提取并正在显示,但是当我点击上一个和下一个按钮时,他们不会页面,也就是说,我保留相同的内容。有人能够从下面的代码中看到错误吗?没有错误或显示所以我认为这是次要的,但我一直在试图找到它的墙上敲我的头

标记:

<asp:Repeater ID="ArtRepeater" runat="server">
<HeaderTemplate>
    <h2>Items in Selected Category:</h2>
</HeaderTemplate>  
<ItemTemplate>
    <li>
        <asp:HyperLink runat="server" ID="HyperLink"
            NavigateUrl='<%# Eval("MovieID", "Default2.aspx?ArtID={0}")%>'>
            <%# DataBinder.Eval(Container.DataItem, "MovieTitle")%>
        </asp:HyperLink>
    </li>
</ItemTemplate>

                 

代码背后:

Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
    doPaging()
End Sub

Function getTheData() As DataTable
        Dim DS As New DataSet()
        Dim strConnect As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source = " & _
        Server.MapPath("/App_Data/MovieBoard.accdb"))
        Dim objOleDBAdapter As New OleDbDataAdapter("SELECT MovieID, MovieTitle FROM Movies", strConnect)
        objOleDBAdapter.Fill(DS, "Movies")

        Return DS.Tables("Movies").Copy
    End Function

    Sub doPaging()
        pagedData.DataSource = getTheData().DefaultView
        pagedData.AllowPaging = True
        pagedData.PageSize = 1

        Try
            pagedData.CurrentPageIndex = Int32.Parse(Request.QueryString("Page")).ToString()
        Catch ex As Exception
            pagedData.CurrentPageIndex = 0
        End Try

        btnPrev.Visible = (pagedData.IsFirstPage)
        btnNext.Visible = (Not pagedData.IsLastPage)

        pageNumber.Text = (pagedData.CurrentPageIndex + 1) & " of " & pagedData.PageCount

        ArtRepeater.DataSource = pagedData
        ArtRepeater.DataBind()
    End Sub

1 个答案:

答案 0 :(得分:0)

在我的头撞墙后,我找到了一个解决方案。我忘了将按钮连接到转发器控件。这是一个解决方案:

Imports System.Data
Imports System.Data.OleDb

Partial Class Default2
Inherits System.Web.UI.Page

Dim pagedData As New PagedDataSource

Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
    doPaging()
End Sub

Function getTheData() As DataTable
    Dim DS As New DataSet()
    Dim strConnect As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source = " & _
    Server.MapPath("/App_Data/MovieBoard.accdb"))
    Dim objOleDBAdapter As New OleDbDataAdapter("SELECT MovieID, MovieTitle FROM Movies", strConnect)
    objOleDBAdapter.Fill(DS, "Movies")

    Return DS.Tables("Movies").Copy
End Function

Sub doPaging()
    pagedData.DataSource = getTheData().DefaultView
    pagedData.AllowPaging = True
    pagedData.PageSize = 1

    Try
        pagedData.CurrentPageIndex = Int32.Parse(Request.QueryString("Page")).ToString()
    Catch ex As Exception
        pagedData.CurrentPageIndex = 0
    End Try

    btnPrev.Visible = (Not pagedData.IsFirstPage)
    btnNext.Visible = (Not pagedData.IsLastPage)

    If Not pagedData.IsFirstPage Then
        btnPrev.PostBackUrl = Request.CurrentExecutionFilePath + _
                                       "?Page=" + CStr(pagedData.CurrentPageIndex - 1)
    End If

    If Not pagedData.IsLastPage Then
        btnNext.PostBackUrl = Request.CurrentExecutionFilePath + _
                                       "?Page=" + CStr(pagedData.CurrentPageIndex + 1)
    End If

    pageNumber.Text = (pagedData.CurrentPageIndex + 1) & " of " & pagedData.PageCount

    ArtRepeater.DataSource = pagedData
    ArtRepeater.DataBind()