[GridView]GridView如何維持顯示Pager

  • 5119
  • 0
  • 2008-12-29

當GridView的PageSize > PageCount時,仍要顯示Pager的作法

當Gridview的PageSize > PageCount時,

會強制使Pager消失。

這對自訂的CumtomPager來說,若Pager上可以自行調整PageSize,可能會導致PageSize變大而無法縮小回來。

有個很炫的作法,只需要重新覆寫PageCount的屬性,針對當CreateChildControl()呼叫時,對PageCount動手腳,

即可讓Pager顯示。

        ''' <summary>
        ''' 只要有資料,就出現pager的作法
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Overrides ReadOnly Property PageCount() As Integer
            Get
                Dim intpageCount As Integer = MyBase.PageCount
                If intpageCount = 1 Then
                    ' Only override the PageCount if the GridView.CreateChildControls is calling
                    Dim sf As New System.Diagnostics.StackFrame(1)
                    If sf.GetMethod().Name = "CreateChildControls" AndAlso sf.GetMethod().ReflectedType Is GetType(GridView) Then
                        intpageCount += 1
                    End If
                End If
                Return intpageCount

            End Get
        End Property

blog 與課程更新內容,請前往新站位置:http://tdd.best/