0

結果を 15 のセットで表示するリピーター リストがあります。[次へ] ボタンをクリックすると、次の 15 が表示されます。

表示をフィルタリングして結果を 10、25、50 のセットで表示するボタンをいくつか追加しました。

これらをクリックすると機能しますが、次のボタンをクリックすると表示値が 15 にリセットされます。

以下は、スクリプトのチャンクです。

Public Property CurrentPage() As Integer
    Get
        ' look for current page in ViewState
            Dim o As Object = Me.ViewState("_CurrentPage")


        If o Is Nothing Then
            Return 0
        Else
            ' default to showing the first page
            Return CInt(o)
        End If
    End Get

    Set
        Me.ViewState("_CurrentPage") = value
    End Set
    End Property

    Protected Sub ItemsGet()
        Dim pageSize As Integer = 15
        ItemsGet(pageSize)
    End Sub

    Private Sub ItemsGet(ByVal pageSize As Integer)
        ' Read sample item info from XML document into a DataSet

        ' Populate the repeater control with the Items DataSet
        Dim objPds As New PagedDataSource()

        Dim selectedCategory As String = ddlCategory.SelectedValue.ToString()
        Dim selectedCategoryIndex As Integer = ddlCategory.SelectedIndex

        Dim selectedCategoryMonth As String = ddlCategoryMonth.SelectedValue.ToString()
        Dim selectedCategoryMonthIndex As Integer = ddlCategoryMonth.SelectedIndex

        Dim query = GetXmlDataSet()

        If (Not String.IsNullOrEmpty(selectedCategory) And selectedCategoryIndex > 0) Then
            query = query.Where(Function(x) x("SCategoryName") = selectedCategory)
        End If
        If (Not String.IsNullOrEmpty(selectedCategoryMonth) And selectedCategoryMonthIndex > 0) Then
            query = query.Where(Function(x) x("SCategoryMonth") = selectedCategoryMonth)
        End If

        If (query.Count() > 0) Then

            objPds.DataSource = query.CopyToDataTable().Rows
            objPds.AllowPaging = True
            objPds.PageSize = pageSize

            objPds.CurrentPageIndex = CurrentPage

            lblCurrentPage.Text = "Page: " + (CurrentPage + 1).ToString() + " of " + objPds.PageCount.ToString()

            ' Disable Prev or Next buttons if necessary
            cmdPrev.Enabled = Not objPds.IsFirstPage
            cmdNext.Enabled = Not objPds.IsLastPage
            Display10.Enabled = True
            Display25.Enabled = True
            Display50.Enabled = True

            categories.DataSource = objPds
            categories.DataBind()
        Else
            CurrentPage = 0
            categories.Controls.Clear()
            cmdPrev.Enabled = False
            cmdNext.Enabled = False
            Display10.Enabled = False
            Display25.Enabled = False
            Display50.Enabled = False
            lblCurrentPage.Text = "Page: 0 of 0 "
        End If
    End Sub

    Private Sub Display10_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim pageSize As Integer = 10
        CurrentPage = 0
        ItemsGet(pageSize)
    End Sub

    Private Sub Display25_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim pageSize As Integer = 25
        CurrentPage = 0
        ItemsGet(pageSize)
    End Sub

    Private Sub Display50_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim pageSize As Integer = 50
        CurrentPage = 0
        ItemsGet(pageSize)
    End Sub



    Private Sub cmdPrev_Click(ByVal sender As Object, ByVal e As System.EventArgs)

        ' Set viewstate variable to the previous page
        CurrentPage -= 1

        ' Reload control
        ItemsGet()
    End Sub

    Private Sub cmdNext_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        ' Set viewstate variable to the next page
        CurrentPage += 1

        ' Reload control
        ItemsGet()
    End Sub


    Protected Sub ddlCategory_SelectedIndexChanged1(ByVal sender As Object, ByVal e As System.EventArgs)
        CurrentPage = 0
        ItemsGet()
    End Sub

    Protected Sub ddlCategoryMonth_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        CurrentPage = 0
        ItemsGet()
    End Sub
4

1 に答える 1

1

取得するアイテムの数を「保持」する必要があります。

これを行うにはいくつかの方法があります....

適切なデフォルト値で初期化することを忘れないでください。

代わりに、このプロパティを使用するように ItemsGet サブルーチンを変更してください。

私のVBは錆びています!

Public Property PageSize() As Integer
    Get
       If Me.ViewState("PageSize") Is Nothing Then
            Me.ViewState("PageSize") = 15
        End If

        Return CInt( Me.ViewState("PageSize") )      
    End Get
    Set
        Me.ViewState("PageSize") = value
    End Set
 End Property
于 2012-09-28T13:42:33.610 に答える