Intersoft WebGrid Documentation
Walkthrough: Updating footer when loading data on demand
See Also Send comments on this topic.

Glossary Item Box

This walkthrough shows you how to update the footer's text when load.

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

 Prerequisites

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

  • Access to the Microsoft Access Northwind database.
  • Visual Studio 2005 Application.

 Step-By-Step Instructions

To create new web application and update footer when loading data on demand.

  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. Drag WebGrid instance from ToolBar to WebForm.
  8. In the Solution Explorer, right-click on App_Data and select Add Existing Item.
  9. Browse and add NorthWind.mdb in C:\Program Files\Intersoft Solutions\Data (Default installation folder).
  10. Click the SmartTag on the upper right of the WebGrid.
  11. In Choose Data Source field, choose <New data source...>.



  12. In Data Source Configuration Wizard, choose ISDataSource and click OK.



  13. Select the Schema Type that you want to use and click Next.



  14. Add Orders tables and click Finish.



  15. Then, choose Retrieve Hierarchical Structure action in Connected to Data Source Control Wizard and click OK.



  16. Right click on ISDataSource1 and launch the designer, set the Orders table's SelectCountMethod to GetCount, SelectMethod to GetData, and EnablePaging to True.



  17. Right click on WebGrid and launch the designer, in Popular Settings - Paging Expandable panel set Paging Mode = "VirtualLoad" and virtual load mode set to "Custom".



  18. Checked Show Column Footer checkbox in User Interface - User Interface settings expandable panel.
  19. In Advanced tab - RootTable - Columns - Freight - See all properties, set AggregateFunction to Count and FooterText = "COUNT = "



  20. Write codes that handle virtual load and the total row count in App_Code (NorthWind.cs).

    C# Copy ImageCopy Code
    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Data.OleDb;
    using NorthWindTableAdapters;
    using System.Data.OleDb;
                                
    namespace NorthWindTableAdapters
    {    
       public partial class OrdersTableAdapter : System.ComponentModel.Component    
       {        
          public DataTable GetData(string customerID)      
          {            
             NorthWind.OrdersDataTable dt = new NorthWind.OrdersDataTable();
                                
             OleDbDataAdapter adapter = new OleDbDataAdapter();            
             adapter.SelectCommand = new OleDbCommand("SELECT * FROM Orders WHERE CustomerID = '" + customerID + "'", this.Connection);            
             adapter.Fill(dt);
            
             return dt;        
          }
                                
           /// <summary>        
           /// This function is used in 5.0\CustomVirtualLoad tutorial.        
           /// </summary>        
           /// <remarks>        
           /// When the WebGrid is configured to use VirtualLoad paging with Custom mode which is bound to ISDataSource,        
           /// the datasource control requires a function which is written by developer to handle the paging logic.        
           /// The function name is determined by the SelectMethod property.        
           /// The paramaters need to be exactly the same as in the following.        
           /// With the function defined in App_Code, the WebGrid does not handle the data retrieval logic any further.        
           /// This results in clean separation between user interface and data component function. The WebGrid will simply        
           /// gets a valid datasource returned by the datasource control. With this separation, WebGrid is now purely functioning        
           /// as data presenter and providing user interface to allow users to interact with the information.        
           /// </remarks>        
           /// <param name="startRowIndex">The start row number. The value is passed from WebGrid control.</param>        
           /// <param name="maximumRows">The maximum rows to retrieve.</param>        
           /// <param name="sortExpression">The sort expression string if any.        
           /// If there is more than one sort column in WebGrid, this sort expression can be passed to your        
           /// SELECT query in order to get correct results.        
           /// </param>        
           /// <returns></returns>        
    
          public DataTable GetData(int startRowIndex, int maximumRows, string sortExpression)        
          {            
             NorthWind.OrdersDataTable dt = new NorthWind.OrdersDataTable();                            
             int topRows = startRowIndex + maximumRows;                            
             if (!string.IsNullOrEmpty(sortExpression))                
                sortExpression = " order by " + sortExpression;
                                
             OleDbDataAdapter adapter = new OleDbDataAdapter();            
             adapter.SelectCommand = new OleDbCommand("SELECT TOP " + topRows.ToString() + " * FROM Orders" + sortExpression, this.Connection);            
             adapter.Fill(dt);
                                
             return dt;        
          }
                                
          /// <summary>        
          /// This function is used in 5.0\CustomVirtualLoad tutorial.        
          /// </summary>        
          /// <remarks>        
          /// In order to create custom virtual load paging functionality, developer is required to write a function        
          /// that retrieves the total rows of the table in the GetData context above.        
          /// The function name is determined by SelectCount property in ISDataSourceTable object.        
          /// The parameters need to be exactly the same as in the following.        
          /// </remarks>        
          /// <param name="sortExpression">The sort expression which is passed from WebGrid control.</param>        
          /// <returns>Returns the count of the virtual rows.</returns>        
    
          public int GetCount(string sortExpression)        
          {            
             OleDbDataAdapter adapter = new OleDbDataAdapter();            
             adapter.SelectCommand = new OleDbCommand("Select COUNT(*) From Orders", this.Connection);
             
             this.Connection.Open();            
             int result = (int)adapter.SelectCommand.ExecuteScalar();            
             this.Connection.Close();
                                
             return result;        
          }    
       }
    }
    

  21. Finally, the WebGrid will look like the following:

See Also

©2012 Intersoft Solutions Corp. All Rights Reserved.