Intersoft WebGrid Documentation
Walkthrough: Applying custom sorting in WebGrid
See Also Send comments on this topic.

Glossary Item Box

This walkthrough shows you how to apply CustomSort in WebGrid.

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 set CustomSort server side event.

  1. Bind WebGrid to AccessDataSource.
  2. Enable AllowEdit.
  3. Set Automatic Sort to false. You can find this property in WebGrid.NET Designer >> Advanced tab >> RootTable >> See all properties.
  4. In the CustomSort server side event of the WebGrid.

    C# Copy Code
    WebGridGroup sortCol;         
    sortCol = e.SortColumns.GetNamedItem("ContactName");
    
    WebGridGroup oldSortCol;         
    oldSortCol = e.SortColumns.GetNamedItem("CustomerID");
    
    if (oldSortCol != null) 
    {             
       sortCol = new WebGridGroup();             
       sortCol.Table = oldSortCol.Table;             
       sortCol.ColumnMember = "ContactName";                         
       
       if (e.SortColumns.GetNamedItem("CustomerID").SortOrder == SortOrder.Ascending) 
       {                 
          sortCol.SortOrder = SortOrder.Ascending;             
       }             
       else if (e.SortColumns.GetNamedItem("CustomerID").SortOrder == SortOrder.Descending) 
       {                 
          sortCol.SortOrder = SortOrder.Descending;             
       } 
       
       e.SortColumns.Remove(oldSortCol); e.SortColumns.Add(sortCol);         
    }
    
  5. Please note to "using ISNet.WebUI.WebGrid"

See Also

©2012 Intersoft Solutions Corp. All Rights Reserved.