Go to a Specific Page in a Table

"You can write a code customization to go to a specific page in a table."
- Mahalakshmi Ramachandran, Software Engineer, Iron Speed, Inc.

March 29, 2006
Iron Speed Designer V3.2

Procedure
You can write a code customization to go to a specific page in a table. One way to do this is to pass the page number on the URL, for example:

http://localhost/MyApp/ShowCustomersTable.aspx?page=4

Handle the Load event for the Page class and set the CurrentPageIndex to the value passed via the URL. Then, call the DataBind() method to refresh the page.

C#:

public class ShowCustomersTablePage : BaseShowCustomersTablePage
{
    public ShowCustomersTablePage()
    {
        this.Load += new EventHandler(Page_Load);
    }
    // Occurs when the server control is loaded on to the Page object.
    private void Page_Load(object sender, System.EventArgs e)
    {
        if (!(this.IsPostBack))
        {
            If (this.Request.QueryString["page"] != null)
            {
                this.CustomersTableControl.CurrentPageIndex = _
                (int.Parse(this.Request.QueryString["page"])) - 1;
                this.DataBind();
            }
        }
    }
} // End class ShowCustomersTablePage

Visual Basic .NET:

Private Sub Page_Load1(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
    If Not (Me.Page.IsPostBack) Then
      If Not ((Me.Request.QueryString("page")) Is Nothing) Then
        Me.CustomersTableControl.CurrentPageIndex = CInt(Me.Request.QueryString("page")) – 1
        Me.DataBind()
      End If
    End If
End Sub

Change the CustomersTableControl to the name of the table control on your page.

Alternatively, you can add a textbox for the user to input the page number. When the user presses the Go button, execute the same two lines of code in the above function to change the page number.

C#:

this.CustomersTableControl.CurrentPageIndex = this.pageNumberTextBox.text;
this.DataBind();

Visual Basic .NET:

Me.CurrentPageIndex = PageNumberTextBox.text
Me.DataBind()

About the Author
Mahalakshmi Ramachandran
Software Engineer, Iron Speed, Inc.

Maha has experience developing Web Applications using the .NET technology and has been with Iron Speed since 2005.

Maha holds an M.S. degree in Computer Engineering from San Jose State University and a B.E. degree in Computer Science and Engineering from India.



  Privacy Statement