Data Access has been discontinued. Please refer to this page for more information.

Filtering Data

This article is relevant to entity models that utilize the deprecated Visual Studio integration of Telerik Data Access. The current documentation of the Data Access framework is available here.

The OpenAccessLinqDataSource control provides a number of services that help you add advanced capabilities to your applications. This includes filtering data. This topic illustrates how to use the OpenAccessLinqDataSource control to filter which records are returned.

Filtering Which Records to Retrieve

The Where tab on the second page of the wizard (the Configure Data Selection dialog) allows you to filter which records to be returned by setting the Where property. If you do not specify a value for the Where property, the OpenAccessLinqDataSource control returns all the records from the database table.

To add one or more conditions to the Where expression:

  1. In the Configure Data Selection dialog of the OpenAccessLinqDataSource Wizard, switch to the Where tab.
  2. Select the Member (the column) that will be used in the filter expression.
  3. Select the comparison Operator.
  4. Select the Source of the parameter. For more information about the different sources, read here.
  5. Specify the Default Value for the parameter.
  6. Click the Add button to create the condition.

The following example shows the markup for part of an ASP.NET Web page that contains an OpenAccessLinqDataSource. The control is configured to enable the user to display all columns from a table named Categories. The returned records are filtered by the CategoryName column. Only records which CategoryName is equal to "SUV" will be returned.

   Where="CategoryName == @CategoryName">
       <asp:Parameter DefaultValue="SUV" Name="CategoryName" Type="String" />

How to: Change the Filter Expression Runtime

To change the filter expression runtime, you need to attach to the Selecting event. The Selecting event occurs before a data-retrieval operation. The OpenAccessLinqDataSourceSelectEventArgs object that is passed to the event handler contains the parameters for the data-retrieval operation. You can modify the parameters in the Selecting event handler before the query executes.

protected void OpenAccessLinqDataSource_Selecting(object sender, 
    Telerik.OpenAccess.Web.OpenAccessLinqDataSourceSelectEventArgs e)
   if (e.WhereParameters.ContainsKey("CategoryName"))
       e.WhereParameters["CategoryName"] = "Saloon";
Protected Sub OpenAccessLinqDataSource_Selecting(ByVal sender As Object, _
    ByVal e As Telerik.OpenAccess.Web.OpenAccessLinqDataSourceSelectEventArgs) _
    Handles OpenAccessLinqDataSource1.Selecting
 If e.WhereParameters.ContainsKey("CategoryName") Then
  e.WhereParameters("CategoryName") = "Saloon"
 End If
End Sub

For a complete UI reference of the Where tab page, check out the Where Settings topic.