ASP.NET
  Home arrow ASP.NET arrow Page 4 - Changing the Page Size Interactively in a ...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP.NET

Changing the Page Size Interactively in a DataGrid Web Control
By: Csaba Hatvany
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 25
    2003-03-31

    Table of Contents:
  • Changing the Page Size Interactively in a DataGrid Web Control
  • The Problem
  • The Solution
  • The Implementation
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Changing the Page Size Interactively in a DataGrid Web Control - The Implementation


    (Page 4 of 5 )

    For convenience we can wrap the work done in a function

    Function NewCurrentPageIndex( _
        dg As DataGrid, _
    ....ntRecordCount As Integer, _
    ....intNewPageSize As Integer _
    ) As Integer

    The SelectedIndexChanged event of our page size setting DropDownList control has the procedure PageSizeChanged as its handler. This procedure looks like that:

    Sub PageSizeChanged(sender As Object, e As EventArgs)
        MyDataGrid.CurrentPageIndex = _
            NewCurrentPageIndex(MyDataGrid, _
                                Session("recCount"), _
                                ddlPageSize.SelectedItem.Text)
        BindGrid
    End Sub

    Here is the source of the NewCurrentPageIndex function:

    Function NewCurrentPageIndex( _
        dg As DataGrid, _
        intRecordCount As Integer, _
        intNewPageSize As Integer _
    ) As Integer
        ' old page size
        Dim intOldPageSize As Integer
        ' top record index on current page
        Dim intFirstRecordIndex As Integer
        ' new page count
        Dim intNewPageCount As Integer
        Dim intNewCurrentPageIndex as Integer
        ' is given from the DataGrid PageSize property
        intOldPageSize = dg.PageSize
        ' identifies the reference record
        intFirstRecordIndex = dg.CurrentPageIndex * intOldPageSize + 1
        ' set the new page size for the Data grig
        dg.PageSize = intNewPageSize
        ' The actual page count of the DataGrid control
        ' is the "old" page count.
        ' The new page count of the DataGrid control will be set
        ' automatically after we bind the Datagrid to the data source
        ' with new page size set.
        ' We need the new page count already now
        ' to find out the new current page index,
        ' so we must calculate it.
        intNewPageCount = _
        CType(Math.Ceiling(intRecordCount / intNewPageSize),Integer)
        ' get the new current page index
        Dim i as Integer
        For i = 1 to intNewPageCount
            If intFirstRecordIndex >= (i-1)*intNewPageSize +1 And _
                intFirstRecordIndex <= i*intNewPageSize Then
                intNewCurrentPageIndex=i-1
                Exit For
            End If
        Next i
        NewCurrentPageIndex = intNewCurrentPageIndex
    End Function

    Here (http://www.hatvany-online.net/aspdotnet/articles/changingpagesize.aspx) you can try a live demo. You can find the source code of the sample in the support file.

    More ASP.NET Articles
    More By Csaba Hatvany


     

    ASP.NET ARTICLES

    - How Caching Means More Ca-ching, Part 2
    - How Caching Means More Ca-ching, Part 1
    - Reading a Delimited File Using ASP.Net and V...
    - What is .Net and Where is ASP.NET?
    - An Object Driven Interface with .Net
    - Create Your Own Guestbook In ASP.NET
    - HTTP File Download Without User Interaction ...
    - Dynamically Using Methods in ASP.NET
    - Changing the Page Size Interactively in a Da...
    - XML Serialization in ASP.NET
    - Using Objects in ASP.NET: Part 1/2
    - IE Web Controls in VB.NET
    - Class Frameworks in VB .NET
    - Cryptographic Objects in C#: Part 1
    - Sample Chapter: Pure ASP.Net







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    Stay green...Green IT