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

Glossary Item Box

When a filter or more is applied to the grid, it will check the column with WebValueList applied to it and then do some manipulation on how data is suppose to be filtered. What it actually does is it filters a column which is not rendered in the grid, not the column you thought you are filtering.

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 Custom Filtering Feature in WebGrid

  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 ChooseDataSource 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 2 or more tables required and click Finish.



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



  16. Set the ValueList from column properties like following:



  17. Select AllowFilter, AllowEdit and AllowSorting properties from SmartTag..



  18. In the code behind, add the following code to the CustomFilter server side event of the grid.

    C# Copy Code
    private void WebGrid1_CustomFilter(object sender, ISNet.WebUI.WebGrid.FilterEventArgs e)
    {
            WebGridFilter filter;
            filter = e.FilterColumns.GetNamedItem("CategoryName");
            if (filter!=null)
                    e.FilterColumns.Remove(filter);
    
            WebGridFilter oldFilter;
            oldFilter = e.FilterColumns.GetNamedItem("CategoryID");
            if (oldFilter!=null)
            {
                    e.FilterColumns.Remove(oldFilter);
                    filter = new WebGridFilter();
                    filter.Table = oldFilter.Table;
                    // remember to set column member field BEFORE FilterType and FilterText
                    filter.ColumnMember = "CategoryName";
                    filter.FilterType = oldFilter.FilterType;
                    filter.FilterText = oldFilter.FilterText;
                    e.FilterColumns.Add(filter);
            }
    }
    

See Also

©2012 Intersoft Solutions Corp. All Rights Reserved.