2013年10月10日 星期四

取得DataPager目前所在頁數的範例程式

備註:
1.DataPagerListView為ListView=>ListViewProductsList使用的DataPager。
2.HiddenFieldCurrentPageNo為存放目前所在頁數。
3.寫在ListViewProductsList的DataBound事件中。

 Private Sub ListViewProductsList_DataBound(sender As Object, e As System.EventArgs) Handles ListViewProductsList.DataBound
        '
        If Me.DataPagerListView.TotalRowCount > 0 Then
            Dim CurrentPageNo As Integer = Math.Ceiling(((Me.DataPagerListView.StartRowIndex + Me.DataPagerListView.MaximumRows) / Me.DataPagerListView.MaximumRows))
            Me.HiddenFieldCurrentPageNo.Value = CurrentPageNo.ToString
            'Me.LabelCurrentPageNo.Text = CurrentPageNo.ToString
        Else
            'Me.LabelCurrentPageNo.Text = "0"
            Me.HiddenFieldCurrentPageNo.Value = "0"
        End If

  End Sub

沒有留言: