Quantcast
Channel: DevExpress Support Center (Examples)
Viewing all articles
Browse latest Browse all 7205

ASPxReportDesigner - How to add/edit/remove DataSourses in the web report designer (Custom DataSource wizard)

$
0
0

This example demonstrates how you can modify the list of DataSources that is passed to the ASPxReportDesigner on the fly. 

Description:
To run the DataSource wizard, open the ASPxReportDesigner menu and press the "Run Report DataSource Editor" item:



After that the Custom DataSource wizard form will be displayed:

On this form you can see the list of DataSources. After one of the data sources is selected in the list you will see the list of its Queries in the right list box. You can add, edit and remove either the DataSources or the Queries by using the buttons located under the lists. After Add... or Edit... buttons are pressed a separate modal form will be displayed to add or edit the selected Data Source or Query. Note that after the Save button is pressed on these forms, the Data Source or Query will be validated, and the error message will be displayed if the Data Source or Query cannot be created. 

When the Apply button is pressed on the wizard form, all the DataSources will be posted to the server. If any exception occurs during these DataSources' creation, an error message will be displayed on the wizard form. Otherwise, the data sources will be available in the Report Designer.
You can add them to your report by pressing a + button in the Field List:

Or by using the built-in Report Wizard that is available in the Report Designer menu:



Implementation Details:

The main idea of this approach is to use the ASPxReportDesigner.DataSources property to pass the set of DataSources to ASPxReportDesigner. To update the set of DataSources passed to the designer dynamically, I have placed the ASPxReportDesinger control into the ASPxCallbackPanel control. So, its callbacks are used to update the entire ASPxReportDesinger. 
The designer's DataSource list is populated on the server dynamically by using the CustomQueryWizardModel class. This class is converted to JSON and passed to the client by using the CustomJSProperties event handler (see the How to: Access Server Data on the Client Side help topic for more information). 
After the Wizard popup form is opened, JSON data passed to the client is converted to the JavaScript object and used to populate a Wizard form. So, this object is used to edit the data source collection on the client side.
When the Apply button is pressed on the Wizard form, the CustomQueryWizardModel object that was edited on the client side is converted to JSON and passed back to the server as a callback parameter. In the server-side ASPxCallbackPanel.Callback event handler, the CustomQueryWizardModel class is restored from the parameter passed form the client and used to update ASPxReportDesigner.DataSources.

Not to lose the report layout designed in ASPxReportDesigner on the ASPxCallbackPanel callback, it is saved by using the client-side ASPxClientReportDesigner.PerformCallback method that triggers a callback on which the report layout is saved and raises the server-side ASPxReportDesigner.SaveReportLayout event handler, where the report layout is saved to the Session. Only after that the ASPxCallbackPanel callback is triggered, and the saved report layout is restored from the Session in the ASPxReportDesigner.Init event handler.

To validate the entered DataSource or Query data on the DataSource and Query editing forms (when the Save button is pressed), the ASPxCallback control is used. It sends a non-visual callback to the server and passes the entered DataSource or Query data to the server. Then, in the ASPxCallback.Callback event handler data passed from the client is used to create a SqlDataSource or CustomSqlQuery instance and check if any errors occur while the creation. The error message is sent back to the client. The client-side ASPxClientCallback.CallbackComplete event handler is used to analyze data that was sent back to the client and to display an error message if required.


Viewing all articles
Browse latest Browse all 7205

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>