# Server-Side Filtering

## Content



We already mentioned that it is generally desirable to restrict the data returned from the server to the client, and we demonstrated how [C1DataSource](/componentone/api/win/online-datasource/dotnet-framework-api/C1.Win.Data.Entity.4.8/C1.Win.Data.Entities.C1DataSource.html) facilitates this with the use of the **FilterDescriptor Collection Editor**. Now we’ll demonstrate how to provide the end user with the means to achieve server-side filtering.

The user will select a _Product_ _Category_ from a combo box, for example, although other GUI controls can be used, and that will load a **DataGrid** with new data from the server.

To implement server-side filtering, follow these steps:

1.  Add a new form with a [C1DataSource](/componentone/api/win/online-datasource/dotnet-framework-api/C1.Win.Data.Entity.4.8/C1.Win.Data.Entities.C1DataSource.html) component to the project used in [Simple Binding](/componentone/docs/win/online-datasource/DesignTimeFeatures/DataBinding). You can make this form the project's start up form to save time when you run the project.
2.  Establish the [C1DataSource](/componentone/api/win/online-datasource/dotnet-framework-api/C1.Win.Data.Entity.4.8/C1.Win.Data.Entities.C1DataSource.html) as before, but this time define two view sources: _Categories_ and _Products_. Click the **Add** button twice in the **ViewSourceCollection**. Enter _Categories_ next to the [EntityViewSourceProperties.EntitySetName](/componentone/api/win/online-datasource/dotnet-framework-api/C1.Data.Entity.4.8/C1.Data.Entities.EntityViewSource.EntitySetName.html) property for the first member (0) and enter _Products_ for the second member (1). For _Products_, we’ll define a filter as shown in the following picture:

![](https://cdn.mescius.io/document-site-files/images/94bcede7-c342-4bf9-97a8-95fb8706d41c/server-side_filtering_files/image001.png)

*   Add a **ComboBox** control to the form and set the following properties:
    *   DataSource = C1DataSource Name (typically C1DataSource1)
    *   DisplayMember = _Categories.CategoryName_
    *   ValueMember = _Categories.CategoryID_
*   Add a **DataGrid** control to the form and set the following properties:
    *   DataSource = C1 DataSource Name (typically C1DataSource1)
    *   DataMember = _Products_
*   Add the following code to the form to handle the combo box’s _SelectedValueChanged_ event:
    
    DOC-DETAILS-TAG-OPEN
    
    DOC-SUMMARY-TAG-OPEN
    
    To write code in Visual Basic
    
    DOC-SUMMARY-TAG-CLOSE
    
    ```vbnet
    Private Sub comboBox1_SelectedIndexChanged(sender As Object, e As EventArgs)
                                    c1DataSource1.ViewSources("Products").FilterDescriptors(0).Value = comboBox1.SelectedValue
                                 End Sub
    ```
    
    DOC-DETAILS-TAG-CLOSE
    
    DOC-DETAILS-TAG-OPEN
    
    DOC-SUMMARY-TAG-OPEN
    
    To write code in C#
    
    DOC-SUMMARY-TAG-CLOSE
    
    ```csharp
    private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
                                 {
                                     c1DataSource1.ViewSources["Products"].FilterDescriptors[0].Value = comboBox1.SelectedValue;
                                 }
    ```
    
    DOC-DETAILS-TAG-CLOSE
    
*   Add the following code to the **Form\_Load** event, to set the **AutoGenerateColumns** property, of the dataGridView control to 'true'.
    
    DOC-DETAILS-TAG-OPEN
    
    DOC-SUMMARY-TAG-OPEN
    
    To write code in Visual Basic
    
    DOC-SUMMARY-TAG-CLOSE
    
    ```vbnet
    dataGridView1.AutoGenerateColumns = True
    ```
    
    DOC-DETAILS-TAG-CLOSE
    
    DOC-DETAILS-TAG-OPEN
    
    DOC-SUMMARY-TAG-OPEN
    
    To write code in C#
    
    DOC-SUMMARY-TAG-CLOSE
    
    ```csharp
    dataGridView1.AutoGenerateColumns = true;
    ```
    
    DOC-DETAILS-TAG-CLOSE
    
*   Save, build and run the application. Select a category in the combo box and notice how products related to that category are displayed in the grid. Switch between categories and notice how the data is returned. As before, all the items in the grid are editable.