Skip to main content

Lesson 1 - Add a Query Builder to a Web Application

  • 2 minutes to read

This lesson will teach you how to add a Query Builder to an ASP.NET Web Forms application.

To get started with this tutorial, create a new ASP.NET Web Forms application containing one Web Form. To add a Query Builder to the created web application, do the following.

  1. Select the default Web Form in the Solution Explorer and click the Design button to open the visual designer for this Web Form.
  2. Expand the DX.23.2: Data and Analytics Toolbox group and drop the ASPxQueryBuilder control onto the page.

    Query-Builder-Add-To-Page

  3. Next, provide the Query Builder with a data connection required to automatically obtain database schema information and properly generate data provider-specific SQL. To achieve this, add an XPO connection string for your database to the application’s Web.config file.

    <connectionStrings>
      <add name="NorthwindXpo" connectionString= 
        "data source=localhost;integrated security=SSPI;initial catalog=nwind.mdf;XpoProvider=MSSqlServer;"/>
    </connectionStrings>
    

    Pass the name of the added connection string to the Query Builder’s ASPxQueryBuilder.OpenConnection method on the Page_Load event as shown in the code sample below.

    protected void Page_Load(object sender, EventArgs e) {
        ASPxQueryBuilder1.OpenConnection("NorthwindXpo");
    }
    
  4. In the application’s Web.config file, add the “resources” section as shown below.

    <devExpress>
        <!-- ... -->
        <resources>
            <add type="ThirdParty" />
            <add type="DevExtreme" />
        </resources>
    </devExpress>
    

    Alternatively, to avoid automatic loading of any libraries by a control (e.g., when such libraries are already referenced on the web page), declare an empty “resources” section and manually attach DevExtreme resources and the required third-party libraries (such as jQuery and Globalize) to the web page.

    <resources>
    </resources>
    

    Deleting the DevExpress “resources” section from the Web.config file will enable the default behavior (with automatic loading only of DevExtreme, without adding third-party libraries).

    To learn more about this configuration, see External Client Libraries.

  5. Run your web application to view the result. Use drag-and-drop to add a data table from the tables list to the current query.

    Query-Builder-Add-Table

    Enable check boxes for data rows that you want to include into the query.

    Query-Builder-Select-Rows

    Click the Preview Results (asp-query-builder-toolbar-preview) toolbar command to preview the results of the query execution.

    Query-Builder-Preview

See Also