Export (0) Print
Expand All

ObjectDataSource::FilterParameters Property

Gets a collection of parameters that are associated with any parameter placeholders in the FilterExpression string.

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

[PersistenceModeAttribute(PersistenceMode::InnerProperty)]
public:
property ParameterCollection^ FilterParameters {
	ParameterCollection^ get ();
}

Property Value

Type: System.Web.UI.WebControls::ParameterCollection
A ParameterCollection that contains a set of parameters associated with any parameter placeholders found in the FilterExpression property.

ExceptionCondition
NotSupportedException

You set the FilterExpression property and the Select method does not return a DataSet or DataTable.

The ObjectDataSource control supports filtering data only when the Select method returns a DataSet or DataTable object.

The syntax that is used for the FilterExpression is a format string–style expression. The filter expression syntax is the same syntax that is accepted by the Expression property. If you add parameters to the FilterParameters collection, you can also include format string placeholders. For example, include "{0}" in the expression to substitute for parameter values. The placeholders are replaced according to the index of the parameter in the FilterParameters collection.

You can include parameters in the FilterExpression property. If the parameter is a string or character type, enclose the parameter in single quotation marks. Quotation marks are not required if the parameter is a numeric type.

The FilterParameters property retrieves the FilterParameters property that is contained by the ObjectDataSourceView object that is associated with the ObjectDataSource control.

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

The following code example demonstrates how to display filtered data using an ObjectDataSource control to retrieve data from a middle-tier business object and 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.

The code example consists of a TextBox control, a GridView control, the ObjectDataSource control, and a Submit button. By default, the TextBox is populated with the name of one of the Northwind Traders employees. The GridView displays information about the employee that is identified by the name in the TextBox. To retrieve data on another employee, in the TextBox, enter 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 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 bounded 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 a numeric or date type, bounding quotation marks are not required. The FilterParameters collection contains one parameter, a FormParameter object that is bound to the TextBox control.

Security noteSecurity Note

You should validate any filter parameter value that you receive from the client. The runtime simply substitutes the parameter value into the filter expression and applies it to the DataView object that is returned by the Select method. If you are using the FilterExpression property as a security measure to limit the number of items that are returned, you must validate the parameter values before the filtering occurs.

No code example is currently available or this language may not be supported.

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:

  • The EmployeeLogic class, which is a class that encapsulates business logic.

  • The NorthwindEmployee class, which 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. It is also helpful for this example, because the sample relies on you to provide the full name of a Northwind Traders employee to demonstrate filtering. 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.

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft