This documentation is archived and is not being maintained.

ObjectDataSourceFilteringEventArgs Class

Provides data for the Filtering event of the ObjectDataSource control.

Namespace: System.Web.UI.WebControls
Assembly: System.Web (in system.web.dll)

public ref class ObjectDataSourceFilteringEventArgs : public CancelEventArgs
public class ObjectDataSourceFilteringEventArgs extends CancelEventArgs
public class ObjectDataSourceFilteringEventArgs extends CancelEventArgs
Not applicable.

The ObjectDataSourceFilteringEventArgs class is used to pass data to the Filtering event handler of the ObjectDataSource control. The ParameterValues property provides access to the filter parameter values before the filtering operation is performed. You can cancel the Select method by setting the Cancel property of the ObjectDataSourceFilteringEventArgs to true.

This section contains two code examples. The first code example demonstrates how to display filtered data by using an ObjectDataSource control to retrieve data from a middle-tier business object, and then using a GridView control to display the results. The second code example provides an example of a middle-tier business object that is used by the first code example.

The following code example demonstrates how to display filtered data by using an ObjectDataSource control to retrieve data from a middle-tier business object, and then using a GridView control to display the results. The ObjectDataSource control can filter data only when the method that retrieves the data retrieves it as a DataSet or DataTable object. For this reason, the SelectMethod property identifies a business object method that retrieves data as a DataSet or DataTable object.

The code example consists of a TextBox control, a GridView control, the ObjectDataSource control, and a Submit button. By default, the TextBox control is populated with the name of one of the employees at Northwind Traders. The GridView control displays information about the employee who is identified by the name in the TextBox. To retrieve data for another employee, in the TextBox control, type the full name of the employee, and then click the Submit button.

The FilterExpression property specifies an expression that is used to filter the data that is retrieved by the method that is specified by the SelectMethod property. It uses parameter placeholders that are evaluated to the parameters that are contained in the FilterParameters collection. In this example, the parameter placeholder is enclosed by single quotation marks (') because the type of the parameter is a string type that might contain spaces. If the type of the parameter is numeric or date, quotation marks are not required. The FilterParameters collection contains one parameter, a FormParameter object that is bound to the TextBox control.

If no name is specified in the TextBox control, a new parameter is added to the ParameterValues collection so that the search is successful.

Security noteSecurity Note:

This example contains a text box that accepts user input, which is a potential security threat. By default, ASP.NET Web pages validate that user input does not include script or HTML elements. For more information, see Script Exploits Overview (Visual Studio).

No code example is currently available or this language may not be supported.
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.JSL" Assembly="Samples.AspNet.JSL" %>
<%@ Page language="VJ#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<script runat="server">

    protected void ObjectDataSource1_Filtering(Object sender, ObjectDataSourceFilteringEventArgs e)
        if (Textbox1.get_Text() == "")
            e.get_ParameterValues().Add("FullName", "Nancy Davolio");

<html xmlns="" >
    <title>ObjectDataSource - VJ# Example</title>
    <form id="Form1" method="post" runat="server">

        <p>Show all users with the following name.</p>

        <asp:textbox id="Textbox1" runat="server" text="Nancy Davolio" />

            <asp:boundfield headertext="ID" datafield="EmpID" />
            <asp:boundfield headertext="Name" datafield="FullName" />
            <asp:boundfield headertext="Street Address" datafield="Address" />

          filterexpression="FullName='{0}'" OnFiltering="ObjectDataSource1_Filtering">
              <asp:formparameter name="FullName" formfield="Textbox1" defaultvalue="Nancy Davolio" />

        <p><asp:button id="Button1" runat="server" text="Search" /></p>


The following code example provides an example of a middle-tier business object that the preceding code example uses. The code example consists of two basic classes: EmployeeLogic and NorthwindEmployee. The EmployeeLogic class encapsulates business logic and the NorthwindEmployee class is a model class that contains only the basic functionality that is required to load and persist data from the data tier. For simplicity, the EmployeeLogic class creates a static set of data, rather than retrieving the data from a data tier. For a complete working example, you must compile and use these classes with the Web Forms code examples that are provided.

No code example is currently available or this language may not be supported.
package Samples.AspNet.JSL ; 
import System .* ;
import System.Collections .* ;
import System.Data .* ;
import System.Web.UI.WebControls .* ;
// EmployeeLogic is a stateless business object that encapsulates 
// the operations you can perform on a NorthwindEmployee object.
public class EmployeeLogic
    // Returns a collection of NorthwindEmployee objects.
    public static ICollection GetAllEmployees()
        ArrayList data = new ArrayList();

        data.Add(new NorthwindEmployee(1, "Nancy", "Davolio", 
            "507 - 20th Ave. E. Apt. 2A"));
        data.Add(new NorthwindEmployee(2, "Andrew", "Fuller", 
            "908 W. Capital Way"));
        data.Add(new NorthwindEmployee(3, "Janet", "Leverling", 
            "722 Moss Bay Blvd."));
        data.Add(new NorthwindEmployee(4, "Margaret", "Peacock", 
            "4110 Old Redmond Rd."));
        data.Add(new NorthwindEmployee(5, "Steven", "Buchanan", 
            "14 Garrett Hill"));
        data.Add(new NorthwindEmployee(6, "Michael", "Suyama", 
            "Coventry House Miner Rd."));
        data.Add(new NorthwindEmployee(7, "Robert", "King", 
            "Edgeham Hollow Winchester Way"));
        return data;
    } //GetAllEmployees

    public static NorthwindEmployee GetEmployee(Object anID)
        ArrayList data = (ArrayList)GetAllEmployees();
        int empID = Int32.Parse(String.valueOf(anID));

        return (NorthwindEmployee)data.get_Item(empID);
    } //GetEmployee

    // To support basic filtering, the employees cannot
    // be returned as an array of objects, rather as a 
    // DataSet of the raw data values. 
    public static DataSet GetAllEmployeesAsDataSet()
        ICollection employees = GetAllEmployees();
        DataSet ds = new DataSet("Table");

        // Create the schema of the DataTable.
        DataTable dt = new DataTable();
        DataColumn dc;

        dc = new DataColumn("EmpID", int.class.ToType());
        dc = new DataColumn("FullName", String.class.ToType());
        dc = new DataColumn("Address", String.class.ToType());

        // Add rows to the DataTable.
        DataRow row;

		IEnumerator iterator = employees.GetEnumerator();
        for (int iCtr = 0; iCtr < employees.get_Count(); iCtr++) {
            NorthwindEmployee ne = 

            row = dt.NewRow();
            row.set_Item("EmpID", ne.get_EmpID());
            row.set_Item("FullName", ne.get_FullName());
            row.set_Item("Address", ne.get_Address());

        // Add the complete DataTable to the DataSet.
        return ds;
    } //GetAllEmployeesAsDataSet
} //EmployeeLogic

public class NorthwindEmployee
    public NorthwindEmployee(int anID, String aFirstName, String aLastName, 
        String anAddress)
        ID = new Integer(anID);
        firstName = aFirstName;
        lastName = aLastName;
        address = anAddress;
    } //NorthwindEmployee

    private Object ID;

    /** @property */
    public String get_EmpID()
        return ID.toString();
    } //get_EmpID

    private String lastName;

    /** @property */
    public String get_LastName()
        return lastName;
    } //get_LastName

    /** @property */
    public void set_LastName(String value)
        lastName = value;
    } //set_LastName

    private String firstName;

    /** @property */
    public String get_FirstName()
        return firstName;
    } //get_FirstName

    /** @property */
    public void set_FirstName(String value)
        firstName = value;
    } //set_FirstName

    /** @property */
    public String get_FullName()
        return firstName + " " + lastName;
    } //get_FullName

    private String address;

    /** @property */
    public String get_Address()
        return address;
    } //get_Address

    /** @property */
    public void set_Address(String value)
        address = value;
    } //set_Address
} //NorthwindEmployee

  • AspNetHostingPermission  for operating in a hosted environment. Demand value: LinkDemand; Permission value: Minimal.
  • AspNetHostingPermission  for operating in a hosted environment. Demand value: InheritanceDemand; Permission value: Minimal.


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0