This is a migrated thread and some comments may be shown as answers.

Web form data set reporting

2 Answers 150 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Chen
Top achievements
Rank 1
Chen asked on 09 Dec 2014, 10:03 AM
I'm referring to http://www.telerik.com/help/reporting/object-data-source-how-to-bind-to-data-set.html just in case my other post will have a reply that I need to use *.aspx for report in MVC for data set...

Right now, I can open the report but it is showing no data. If SELECT Name, ProductCategoryID FROM Production.ProductCategory where ProductCategoryID < 4, it will actually show 3 row of data (direct query from database), but instead, what I get is a repeat of the header 3 times. If I omit the where statement from the sql query, it will show 4 row of data, and the web page report also will show the header 4 times...

I'll appreciate help (or working project file Q3 2014, visual studio 2013)

Default.cs
========


        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                var objectDataSource = new Telerik.Reporting.ObjectDataSource();
                objectDataSource.DataSource = GetAllData(); // GetData returns a DataSet with three tables

                objectDataSource.DataMember = "ProductCategory";

                //Telerik.Reporting.Report report = new Telerik.Reporting.Report();
                Report2 report = new Report2(); //added this instead...

                report.DataSource = objectDataSource;

                Telerik.Reporting.InstanceReportSource reportSource = new Telerik.Reporting.InstanceReportSource();
                reportSource.ReportDocument = report;

                reportViewer1.ReportSource = reportSource;

                reportViewer1.RefreshReport();
            }
        }


        static DataSet GetAllData()
        {
            const string connectionString =
                "Data Source=.;Initial Catalog=AdventureWorks;Integrated Security=True";

            string selectCommandText = "SELECT Name, ProductCategoryID FROM Production.ProductCategory where ProductCategoryID < 4;;" +
                "SELECT Name, ProductCategoryID FROM Production.ProductSubcategory;" +
                "SELECT Name, ProductNumber FROM Production.Product;";

            SqlDataAdapter adapter = new SqlDataAdapter(selectCommandText, connectionString);
            DataSet dataSet = new DataSet();

            adapter.Fill(dataSet);

            dataSet.Tables[0].TableName = "ProductCategory";
            dataSet.Tables[1].TableName = "ProductSubcategory";
            dataSet.Tables[2].TableName = "Product";
            return dataSet;
        }

2 Answers, 1 is accepted

Sort by
0
Nasko
Telerik team
answered on 12 Dec 2014, 08:36 AM
Hello Chen,

The provided code snippet is correct. The described issue should not be caused by the code in the Page_Load or GetAllData methods.  
The issue probably lies in the report definition of Report2 and how the report items are placed inside the report sections. In order to help you further we will need to see your report definition, or a runnable sample project exhibiting the described behavior.

Regards,
Nasko
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Nasko
Telerik team
answered on 12 Dec 2014, 09:59 AM
Hello Chen,

To follow up my last reply, I noticed that you are using a report item in Report2's detail section which looks a lot like the Table report item. Note that the Table item is a Data Item, which means it has its own data source.
You need to set the Table.DataSource in order to display data in the Table item. Instead, you are setting the report.DataSource = objectDataSource in the provided sample code.
This will result in the whole report's detail section repeating itself (together with the table) for each data row in the report's data source.
In order to change this behavior, you need to set the Table.DataSource instead of the Report.DataSource as in the following sample:
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        var objectDataSource = new Telerik.Reporting.ObjectDataSource();
        objectDataSource.DataSource = GetAllData(); // GetData returns a DataSet with three tables
        objectDataSource.DataMember = "ProductCategory";
 
        //Telerik.Reporting.Report report = new Telerik.Reporting.Report();
        Report2 report = new Report2(); //added this instead...
 
        var table = report.Items.Find("table1", true)[0] as Telerik.Reporting.Table;
        table.DataSource = objectDataSource;
 
        Telerik.Reporting.InstanceReportSource reportSource = new Telerik.Reporting.InstanceReportSource();
        reportSource.ReportDocument = report;
        reportViewer1.ReportSource = reportSource;
        reportViewer1.RefreshReport();
    }
}

The approach for retrieving the table item programmatically can be found in the reporting documentation: Access items from report, calling application and Table.

Regards,
Nasko
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
General Discussions
Asked by
Chen
Top achievements
Rank 1
Answers by
Nasko
Telerik team
Share this question
or