Back to Devexpress

Lesson 2 - Use the Resulting Query

aspnet-115131-components-query-builder-getting-started-lesson-2-use-the-resulting-query.md

latest2.3 KB
Original Source

Lesson 2 - Use the Resulting Query

  • Dec 17, 2020
  • 3 minutes to read

This lesson will teach you how to use a SQL query string generated by the ASP.NET Query Builder control to supply DevExpress data-aware web controls with data.

  1. Open the web application created in the Lesson 1 of this tutorial and add a new Web Form to the project.

  2. Select the newly added Web Form in the Solution Explorer and click the Design button to open the visual designer for this web form.

  3. Expand the DX.25.2: Data and Analytics Toolbox tab and drop the ASPxGridView control onto the page.

  4. Switch to the Web Form containing the Query Builder added in Lesson 1 and handle the ASPxQueryBuilder.SaveQuery event. This event occurs on the server side every time the Query Builder’s Save ( ) toolbar command is clicked and provides access to the resulting query string. Add the following code to the handler to save the query string and redirect a browser to the page containing a Grid View.

  5. Add a provider-specific connection string that will be used by the Grid View to the application’s Web.config file.

  6. Switch to the Web Form containing the Grid View. On the Page_Load event, call the ASPxWebControl.DataBind method of the Grid View. Next, handle the System.Web.UI.Control.DataBinding event of the Grid View to bind it to data using the SQL query generated by the Query Builder as show below.

  7. Run your web application, use the Query Builder to construct a query and click the Query Builder’s Save toolbar command to view the result.

See Also

Lesson 1 - Add a Query Builder to a Web Application

Obtaining and Saving the Resulting Query