Saturday, May 25, 2019

DevExpress Report Basic Operations

Here are some basic operations performed with dev express reports.
(1) Display Report as LandScape

- Set report landscape property to true
this.Landscape = true;
- Set Page width
this.PageWidth = 1500;
- Define paperkind property
this.PaperKind = System.Drawing.Printing.PaperKind.LegalExtra;
- to show this report as landscapre your ReportToolbar should have width set to width that you want

(2) Access Report's controls: If there needs way where you have to load your report dynamically and before load it you want to assign/change value of your report's controls then perform below steps.
- make control public
On your report, suppose there is one label "Label1", then set its "Modifiers" property to public

- once above step is done, after your report declaration access this label below way
subReport subReporDetail = new subReport();
subReporDetail.Label1.Text = "Your Text";

- Once you are done with report control property changes then load that report dynamically and your label will be loaded with text you have set.

(3) Dynamically assign datasource: Suppose you are loading your report dynamically but before loading it you want to assign its datasource fetch from API/database then follow below steps
- define your report, subReport and datasource
XRSubreport subReport = new XRSubreport();
myDataSource dsource = new myDataSource();
myReport rpt1 = myReport();

- fetch your datasource 
DataTable dt= fetch data from API/database

- assign your service data to datasource
dsource.EnforceConstraints = false;
dsource.Tables["DataTableName"].Merge(dt);

- assign source and then load it to subreport
rpt1.DataSource = dsource.Tables["DataTableName"];
subReport.ReportSource = subReporDetail;

- Once your subreport has been bind with report and its dynamic data, load it dynamically.

(4) Add Button to ReportToolbar
- To add new button to your report toolbar, add like below way

- write client side events to button click callback
                    if (e.item.name == 'rptcustomevent') {
                        Callback1.PerformCallback(e.item.name);
                    }
                }" />
- write callback function at your javascript
$("#dashboard_menu_custom_button_id").click(function () {
... on click of above button, it will comes to here for your logic on button click
});