A fully functional DataGrid page example

xiaoxiao2021-03-05  22

The following example provides the paging function of the DataGrid. The ASPX code and the COHE BEHIND code are as follows, respectively, respectively, change the data record connection string. The results are as follows: DataGridPaging.aspx program code <% @ page language = "vb" autoeventwireup = "false" codebehind = "DataGridPaging.aspx.vb" inherits = "DataGridPaging"%>

DataGridPaging.aspx.vb Imports System.Data.SqlClient Imports System.Data Imports System.Web.UI Public Class DataGridPaging Inherits System.Web.UI.Page Protected WithEvents MyDataGrid As System.Web.UI.WebControls.DataGrid Protected WithEvents btnFirst As System .Web.UI.WebControls.LinkButton Protected WithEvents btnPrev As System.Web.UI.WebControls.LinkButton Protected WithEvents btnNext As System.Web.UI.WebControls.LinkButton Protected WithEvents btnLast As System.Web.UI.WebControls.LinkButton Protected WithEvents lblCurrentIndex As System.Web.UI.WebControls.Label Protected WithEvents lblPageCount As System.Web.UI.WebControls.Label Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid #Region "Web Form Designer Generated Code" 'This call is required By The Web Form Designer.

Private Sub InitializeComponent () End Sub Private Sub Page_Init (ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Init 'CODEGEN: This method call is required by the Web Form Designer' Do not modify it using the code editor. InitializeComponent () End Sub #End Region Private Sub Page_Load (ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load btnFirst.Text = "most Home" btnPrev.Text = "Previous "btnNext.Text =" Next "btnLast.Text =" last page "OpenDatabase () BindGrid () End Sub Sub MyDataGrid_Page (ByVal sender As Object, ByVal e As DataGridPageChangedEventArgs) Dim startIndex As Integer startIndex = MyDataGrid.CurrentPageIndex * myDataGrid .PageSize MyDataGrid.CurrentPageIndex = e.NewPageIndex BindGrid () ShowStats () End Sub Sub BindGrid () Dim myConnection As SqlConnection = cn Dim ds As DataSet = New DataSet () Dim adapter As SqlDataAdapter = New SqlDataAdapter ( "Select * from Orders" , myconnection) Adapter.Fill (DS, "Orders") MyDataGrid.DataSource = DS.TABLE s ( "Orders"). DefaultView MyDataGrid.DataBind () ShowStats () End Sub Sub PagerButtonClick (ByVal sender As Object, ByVal e As EventArgs) 'used by external paging UI Dim arg As String = sender.CommandArgument Select Case arg Case " next "If (MyDataGrid.CurrentPageIndex <(MyDataGrid.PageCount - 1)) Then MyDataGrid.CurrentPageIndex = 1 End If Case" prev "If (MyDataGrid.CurrentPageIndex> 0) Then MyDataGrid.CurrentPageIndex - = 1 End If Case" last " MyDataGrid.currentpageIndex = (MyDataGrid.pagecount - 1) Case else 'page number mydatagrid.currentpageIndex =

转载请注明原文地址:https://www.9cbs.com/read-37916.html

New Post(0)