ASP.NET(VB.NET)版的?
ASP.NET(VB.NET)版的?
存储过程
CREATE PROCEDURE Page
@PageNo int, --页数
@PageSize int --页大小4
AS
Declare @sN varchar(10)
Declare @sNP varchar(10)
Set @sN=Convert(varchar(10), @PageSize)
Set @sNP=Convert(varchar(10), (@PageNo-1)*@PageSize)
print('Select top '+@sN+' * From Titles ' +
'Where title_ID not in(Select top '+@sNP+' title_ID From Titles order by title_ID) order by title_ID')
Exec('Select top '+@sN+' * From Titles ' +
'Where title_ID not in(Select top '+@sNP+' title_ID From Titles order by title_ID) order by title_ID')
GO
Namespace PRB.PRB
Public Class GridControl
#Region "Declare Region"
Dim _DataGrid As DataGrid
Public Delegate Sub _DataBind()
'Public Event _ResetDataSource As _DataBind
Public _ResetDataSource As _DataBind
#End Region
#Region "構造函式"
''' -----------------------------------------------------------------------------
''' <summary>
''' 函數名稱: GridPagingNation()
''' function說明:構造函式
''' </summary>
''' <param name="obj_DataGrid">執行分頁的DataGrid</param>
''' <param name="e_aResetDataSource">重加載數據源的方法回調</param>
''' <remarks>
''' </remarks>
''' <history>
''' xx. YYYY/MM/DD VER AUTHOR COMMENTS(說明修改的內容)
''' 1. 2006/06/05 1.00 Sunny CREATE
''' </history>
''' -----------------------------------------------------------------------------
Public Sub GridPagingNation(ByVal obj_DataGrid As DataGrid, ByVal e_aResetDataSource As _DataBind)
_ResetDataSource = e_aResetDataSource
_DataGrid = obj_DataGrid
Dim i_Current As Integer
i_Current = obj_DataGrid.CurrentPageIndex
End Sub
#End Region
#Region "Definition Public Methods"
''' -----------------------------------------------------------------------------
''' <summary>
''' 函數名稱: Previous()
''' function說明:上一頁
''' </summary>
''' <param name="btnPrevious">上一頁Button</param>
''' <param name="btnNext">下一頁Button</param>
''' <param name="e_aResetDataSource">重加載數據源的方法回調</param>
''' <remarks>
''' </remarks>
''' <history>
''' xx. YYYY/MM/DD VER AUTHOR COMMENTS(說明修改的內容)
''' 1. 2006/06/05 1.00 Sunny CREATE
''' </history>
''' -----------------------------------------------------------------------------
Public Function Previous(ByVal btnPrevious As LinkButton, ByVal btnNext As LinkButton) 'ByVal e_aResetDataSource As _DataBind
Dim i_Current As Integer
Dim i_MaxPage As Integer
i_Current = _DataGrid.CurrentPageIndex
i_MaxPage = _DataGrid.PageCount - 1
btnNext.Enabled = True
If (i_Current = 0) Then
_DataGrid.Page.RegisterStartupScript("GridPaginationError", "<script>alert('已到頁首!')</script>")
Else
i_Current = i_Current - 1
If (i_Current = 0) Then
btnPrevious.Enabled = False
Else
btnPrevious.Enabled = True
End If
_DataGrid.CurrentPageIndex = i_Current
_ResetDataSource.Invoke()
End If
End Function
''' -----------------------------------------------------------------------------
''' <summary>
''' 函數名稱: NextPage()
''' function說明:構造函式
''' </summary>
''' <param name="btnPrevious">上一頁Button</param>
''' <param name="btnNext">下一頁Button</param>
''' <param name="DataTable">數據源</param>
''' <remarks>
''' </remarks>
''' <history>
''' xx. YYYY/MM/DD VER AUTHOR COMMENTS(說明修改的內容)
''' 1. 2006/06/05 1.00 Sunny CREATE
''' </history>
''' -----------------------------------------------------------------------------
Public Function NextPage(ByVal btnPrevious As LinkButton, ByVal btnNext As LinkButton)
Dim i_Current As Integer
Dim i_MaxPage As Integer
Dim dt As DataTable
i_Current = _DataGrid.CurrentPageIndex
i_MaxPage = _DataGrid.PageCount - 1
btnPrevious.Enabled = True
If (i_Current = i_MaxPage) Then
_DataGrid.Page.RegisterStartupScript("GridPaginationError", "<script>alert('已到頁尾!')</script>")
Else
i_Current = i_Current + 1
If (i_Current = i_MaxPage) Then
btnNext.Enabled = False
Else
btnNext.Enabled = True
End If
_DataGrid.CurrentPageIndex = i_Current
_ResetDataSource.Invoke()
End If
End Function
''' -----------------------------------------------------------------------------
''' <summary>
''' 函數名稱: FristPage()
''' function說明:第一頁
''' </summary>
''' <param name="btnPrevious">上一頁Button</param>
''' <param name="btnNext">下一頁Button</param>
''' <param name="DataTable">數據源</param>
''' <remarks>
''' </remarks>
''' <history>
''' xx. YYYY/MM/DD VER AUTHOR COMMENTS(說明修改的內容)
''' 1. 2006/06/05 1.00 Sunny CREATE
''' </history>
''' -----------------------------------------------------------------------------
Public Function FristPage(ByVal btnPrevious As LinkButton, ByVal btnNext As LinkButton)
Dim i_Current As Integer
Dim i_MaxPage As Integer
i_Current = _DataGrid.CurrentPageIndex
i_MaxPage = _DataGrid.PageCount - 1
If i_Current = 0 Then
_DataGrid.Page.RegisterStartupScript("GridPaginationError", "<script>alert('已到頁首!')</script>")
Else
_DataGrid.CurrentPageIndex = 0
_ResetDataSource.Invoke()
btnPrevious.Enabled = False
btnNext.Enabled = True
End If
End Function
''' -----------------------------------------------------------------------------
''' <summary>
''' 函數名稱: LastPage()
''' function說明:最後一頁
''' </summary>
''' <param name="btnPrevious">上一頁Button</param>
''' <param name="btnNext">下一頁Button</param>
''' <param name="DataTable">數據源</param>
''' <remarks>
''' </remarks>
''' <history>
''' xx. YYYY/MM/DD VER AUTHOR COMMENTS(說明修改的內容)
''' 1. 2006/06/05 1.00 Sunny CREATE
''' </history>
''' -----------------------------------------------------------------------------
Public Function LastPage(ByVal btnPrevious As LinkButton, ByVal btnNext As LinkButton)
Dim i_Current As Integer
Dim i_MaxPage As Integer
i_Current = _DataGrid.CurrentPageIndex
i_MaxPage = _DataGrid.PageCount - 1
If i_Current = i_MaxPage Then
_DataGrid.Page.RegisterStartupScript("GridPaginationError", "<script>alert('已到頁尾!')</script>")
Else
_DataGrid.CurrentPageIndex = i_MaxPage
_ResetDataSource.Invoke()
btnPrevious.Enabled = True
btnNext.Enabled = False
End If
End Function
''' -----------------------------------------------------------------------------
''' <summary>
''' 函數名稱: LastPage()
''' function說明:初始化頁面時Button上一頁和Button下一頁的狀態
''' </summary>
''' <param name="btnPrevious">上一頁Button</param>
''' <param name="btnNext">下一頁Button</param>
''' <param name="DataTable">數據源</param>
''' <remarks>
''' </remarks>
''' <history>
''' xx. YYYY/MM/DD VER AUTHOR COMMENTS(說明修改的內容)
''' 1. 2006/06/05 1.00 Sunny CREATE
''' </history>
''' -----------------------------------------------------------------------------
Public Function Page_Load(ByVal btnPrevious As LinkButton, ByVal btnNext As LinkButton)
Dim i_Current As Integer
Dim i_MaxPage As Integer
Dim i_MinPage As Integer
i_Current = _DataGrid.CurrentPageIndex
i_MaxPage = _DataGrid.PageCount - 1
i_MinPage = 0
If i_Current = i_MinPage Then
btnPrevious.Enabled = False
Else
btnPrevious.Enabled = True
End If
If i_Current = i_MaxPage Then
btnNext.Enabled = False
Else
btnNext.Enabled = True
End If
End Function
#End Region
End Class
End Namespace