[asp.net]如何將grid加入分頁(假定用datasource控制資料來源)(indexChange,paging,e.newPageIndex)

  • 3729
  • 0
  • 2012-06-01

摘要:[asp.net]如何將grid加入分頁(假定用datasource控制資料來源)

先設定好grid的屬性AllowPaging=true  PageSize=3

然後設定grid的pageIndexChanging事件


Protected Sub dtGrid_PageIndexChanging(sender As Object, e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles dtGrid.PageIndexChanging

End Sub

最後在pageIndexChanging裡面加入程式碼,搞定!!,其實說穿了,跟查詢的指令比較起來,只是多一行 dtGrid.PageIndex = e.NewPageIndex而已


 Dim dt As DataTable = New DataTable()
        Dim strSQL As String = ""
        strSQL = " select * from MyEmployees "
        dt = Me.GetDataTable(strSQL)
        dtGrid.DataSource = dt
        dtGrid.PageIndex = e.NewPageIndex
        dtGrid.DataBind()