Intersoft WebGrid Documentation
Walkthrough: Implementing Custom Paging using ObjectDataSource
See Also Send comments on this topic.

Glossary Item Box

This walkthrough shows you how to implement custom paging using ObjectDataSource.

During this walkthrough, you will learn how to do the following:

 Prerequisites

In order to complete this walkthrough, you will need the following:

  • Set EnablePaging od the datasource control to True.
  • Provides a method for Select. This method requires three parameters: startRow, maximumRows, and sortExpression.
  • Provides a method for SelectCount.
  • Visual Studio 2005 Application.

 Step-By-Step Instructions

To create new web application and bind WebGrid to AccessDataSource

  1. Launch Visual Studio.NET 2005.
  2. Click on File menu, then select New and click Web Site.
  3. Select ASP.NET Web Site in the Template box and set Location to HTTP.
  4. Named the Web Site and click OK.
  5. Right-click on Project's name and select Add New Item.
  6. Select Intersoft AppForm in the My Templates box and named it as Walkthrough.aspx.
  7. Right-click on Project's name and select Add New Item.
  8. Choose DataSet and named it NorthWind.



  9. Add Customers table to the dataset.



  10. Right-click on Project's name and select Add New Item.
  11. Choose Class and named it NorthWind.



  12. Create Select method and SelectCount in the class (NorthWind.cs).

    C# Copy ImageCopy Code
    namespace NorthWindTableAdapters
    {
    public partial class CustomersTableAdapter
    {
    public DataTable GetData(int startRowIndex, int maximumRows, string sortExpression)
    {
    NorthWind.CustomersDataTable dt = new NorthWind.CustomersDataTable();
                int topRows = startRowIndex + maximumRows;        
    
                if (!string.IsNullOrEmpty(sortExpression))
    sortExpression = " order by " + sortExpression;
                OleDbDataAdapter adapter = new OleDbDataAdapter();
    adapter.SelectCommand = new OleDbCommand();
    adapter.SelectCommand.CommandText = "Select TOP " + topRows.ToString() + " * FROM Customers" + sortExpression;
    adapter.SelectCommand.Connection = this.Connection;
                adapter.Fill(dt);             
    
                return dt;
    }
    public int SelectCount(string sortExpression)
    {
    this.Connection.Open();
    OleDbDataAdapter adapter = new OleDbDataAdapter();
    adapter.SelectCommand = new OleDbCommand();
    adapter.SelectCommand.CommandText = "Select COUNT(*) From Customers";
    adapter.SelectCommand.Connection = this.Connection;
                int result = (int)adapter.SelectCommand.ExecuteScalar();
    this.Connection.Close();
                return result;
    }
    }
    }

  13. Drag WebGrid instance from ToolBar to WebForm.
  14. Click the SmartTag on the upper right of the WebGrid.
  15. In Choose Data Source field, choose <New data source...>.

     

  16. In Data Source Configuration Wizard, choose Object and click OK.



  17. Select your Business Object and click Next.



  18. Click Finish afterwards.



  19. Finally, choose Retrieve Structure action in Connected to Data Source Control Wizard and click OK.



  20. Set the WebGrid's properties as following:

    Property Value
    PagingLoadMode Custom
    PagingMode ClassicPaging
    PagingStyleUI Slider

  21. Set the ObjectDataSource's properties as following:

    Property Value
    EnablePaging True
    SelectCountMethod SelectCount

  22. Run the project and the WebGrid will look like following.

See Also

©2012 Intersoft Solutions Corp. All Rights Reserved.