Paging Certain # records per page .NET style

 

Contributed by
Rating: 2 stars2 stars2 stars2 stars2 stars / 12
June 01, 2003
Rate this Article:
MEH MEH++


SEARCH ASP FREE
TOOLS YOU CAN USE

advertisement


<SCRIPT language=VB runat="server">

    
Sub Page_Load(sender As ObjectAs EventArgs
       
BindGrid
    End Sub

    Sub MyDataGrid_Page
(sender As ObjectAs DataGridPageChangedEventArgs
    
dim startIndex as Integer
        startIndex 
MyDataGrid.CurrentPageIndex MyDataGrid.PageSize
    MyDataGrid
.CurrentPageIndex e.NewPageIndex

        BindGrid
    ShowStats
    End Sub

    Sub BindGrid
()

        
Dim myConnection As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("DSN_pubs"))
    
dim ds as DataSet = new DataSet()
    
dim adapter as SqlDataAdapter = new SqlDataAdapter("Select * from Authors"myConnection)
    
adapter.Fill(ds,"Authors")

        
MyDataGrid.DataSource=ds.Tables("Authors").DefaultView
        MyDataGrid
.DataBind()
        
ShowStats

    End Sub

    Sub PagerButtonClick
(sender As ObjectAs EventArgs)
        
'used by external paging UI
        Dim arg As string = sender.CommandArgument

        Select 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 System.Convert.ToInt32(arg)
        
End Select
        BindGrid
    ShowStats
    End Sub

    Sub ShowStats
()
        
lblCurrentIndex.Text "CurrentPageIndex is " MyDataGrid.CurrentPageIndex
        lblPageCount
.Text "PageCount is " MyDataGrid.PageCount
    End Sub
 </SCRIPT>

blog comments powered by Disqus
ASP.NET CODE ARTICLES

- How to Use the ListBox Control in ASP.NET 2.0
- How to Load XML Documents in ASP.NET 2.0
- DataGrid Code
- ASP.NET Guestbook
- User Controls and Client Side Scripting
- ASP.NET Programming with Microsoft's AS...
- ASP.NET Basics (part 3): Hard Choices
- ASP.NET Basics (part 2): Not My Type
- ASP.NET Basics (part 1): Nothing But .Net
- Directory Tree Browser
- How to get the confirmation of Yes/No from a...
- Complete example using custom errors and wri...
- Paging Certain # records per page .NET style
- General Methods of formatting and Subtractin...
- .NET LinkButton web control

ASP Web Hosting ASP.Net Web Hosting Windows Web Hosting
 
 
 

ASP Free Forums 
 RSS  Tutorials RSS
 RSS  Forums RSS
 RSS  All Feeds
Site Map 
Request Media Kit
Write For Us Get Paid 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Privacy Policy 
Support 


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 4 - Follow our Sitemap
Most Popular Topics
All ASP.Net Tutorials