1

我正在尝试在转发器控件中创建寻呼机。内容正在从数据库中提取并显示,但是当我单击上一个和下一个按钮时,它们不会分页,也就是说,我停留在相同的内容上。任何人都可以从下面的代码中看到错误吗?没有错误或显示,所以我认为这是小问题,但我一直在用头撞墙试图找到它

标记:

<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
4

1 回答 1

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()
于 2012-12-21T21:05:25.590 回答