# Sort Data

## Content



Sorting is another way to organize data. It can be either ascending or descending. FlexReport allows sorting through **DataSource.SortDefinition**. Let us suppose you want to display product details with their names in ascending order in the report created in [Quick Start](/componentone/docs/reporting/online-flexreport/reportsinwinforms/winquickstart). For doing so, follow these steps to sort the product names in alphabetical order.

1.  Add a **C1Button** to the form and set its **Name** property to **btnSortData and Text** property to **Sort Product by Name**.
2.  Create **Click** event for the button, named as btnSortData\_Click.
3.  Add the following code to the btnSortData\_Click event handler to sort the product names in the Product Report in ascending order.
    
    ```csharp
    bool asc;
    private void btnSortData_Click(object sender, EventArgs e)
    {
        if (asc)
        {
            SortDefinition sd = new SortDefinition("[Name]", SortDirection.Ascending);
            flexReport.DataSource.SortDefinitions.Add(sd);
            asc = false;
        }
        else
        {
            btnLoad.PerformClick();
            asc = true;
        }
    }
    ```
    
4.  Click Sort Product by Name button to view sorting in report as shown in the below image.
    
    ![flexreport-sorting-output](https://cdn.mescius.io/document-site-files/images/4f10fc8d-eb38-4687-8264-468b8828236a/images/flexreport-sorting-output.png)