Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
ASP.NET Datagrid Paging
Author:
bhar
Website:
http://vkinfotek.com
Submitted:
12/13/2005
Version:
ASP.NET 1.1
Compatibility:
ASP.NET 1.1
Category:
ASP.NET
Views:
48555
Here is a sample code for ASP.NET DataGrid paging.
Declarations:
The DataGrid control has built-in support for paging through the records of a data source. For example, there may be a large number of records in the AccountsTable. If we divide the records into multiple pages, it is convenient for the user to see the data. We enable paging for a DataGrid by enabling the AllowPaging property and creating a subroutine to change the current page. This example displays five records at a time from the AccountsTable. By clicking the < and > links displayed at the bottom of the DataGrid, we can navigate forward or backward. A new page is selected with the drdaccounts_pageIndexChanged subroutine. This subroutine assigns the value of the NewPageIndex to the DataGrid control's CurrentPageIndex. The subroutine then rebinds the DataGrid to the data source, displaying the new page of records.
Code:
DatagridPaging
Write the following code in the Code behind window Imports System.Data.SqlClient Dim myConnection As SqlConnection = New SqlConnection("Data Source=SYS1;Integrated Security=SSPI;Initial Catalog=FinAccounting") Const strSQL As String = "SELECT AccountCode,Accountname,AccountDescription FROM AccountsTable" Dim myDataAdapter As SqlDataAdapter = New SqlDataAdapter(strSQL, myConnection) Dim dstaccounts As New DataSet() Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If Not IsPostBack() Then BindDataGrid() End If End Sub Sub BindDataGrid() myConnection.Open() myDataAdapter.Fill(dstaccounts, "AccountsTable") dgrdAccounts.DataSource = dstaccounts dgrdAccounts.DataBind() End Sub Sub drdaccounts_pageIndexChanged(ByVal s As Object, ByVal e As DataGridPageChangedEventArgs) dgrdAccounts.CurrentPageIndex = e.NewPageIndex BindDataGrid() End Sub
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement