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

Create Report programmatically

1 Answer 925 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
IMF
Top achievements
Rank 1
IMF asked on 15 Jun 2015, 09:26 AM

Hello,

 

I need to create a report programmatically and watch this report in a report viewer when i push a button for print this. I have read information but i can't resolve it. This is my code:

 

 

protected void Page_Load(object sender, EventArgs e)
   {
       doReport();
   }
 
   private void doReport()
   {
       DataTable table = new DataTable();
       table.Columns.Add("Col1", typeof(string));
       table.Columns.Add("Col2", typeof(string));
       table.Columns.Add("Col3", typeof(string));
       table.Columns.Add("Col4", typeof(string));
 
       List<datos> datosList = new List<datos>();
       datosList.Add(new datos { dato1 = " lala", dato2 = "lele", dato3 = "lili", dato4 = "lolo" });
       datosList.Add(new datos { dato1 = " lala", dato2 = "lele", dato3 = "lili", dato4 = "lolo" });
       datosList.Add(new datos { dato1 = " lala", dato2 = "lele", dato3 = "lili", dato4 = "lolo" });
       datosList.Add(new datos { dato1 = " lala", dato2 = "lele", dato3 = "lili", dato4 = "lolo" });
 
       for (int i = 0; i < datosList.Count; i++)
       {
           string dato1 = datosList[i].dato1;
           string dato2 = datosList[i].dato2;
           string dato3 = datosList[i].dato3;
           string dato4 = datosList[i].dato4;
           table.Rows.Add(dato1, dato2, dato3, dato4);
       }
 
       Telerik.Reporting.ObjectDataSource objectDataSource = new Telerik.Reporting.ObjectDataSource();
       objectDataSource.DataSource = table;
       objectDataSource.CalculatedFields.Add(new Telerik.Reporting.CalculatedField("FullName", typeof(string), "=Fields.PagePath + ' ' + Fields.Pageviews")); // Adding a sample calculated field.
 
 
       Telerik.Reporting.Report report = new Telerik.Reporting.Report();
       report.Name = "prueba";
       report.DocumentName = "prueba";
       report.DataSource = objectDataSource;
 
       Telerik.Reporting.InstanceReportSource reportSource = new Telerik.Reporting.InstanceReportSource();
       reportSource.ReportDocument = report;
 
       ReportViewer1.ReportSource = reportSource;
 
       ReportViewer1.RefreshReport();
   }
 
   public class datos
   {
       public datos()
       {}
 
       public string dato1 ;
       public string dato2 ;
       public string dato3 ;
       public string dato4 ;
   }

 

Any idea? Thanks

1 Answer, 1 is accepted

Sort by
0
Stef
Telerik team
answered on 15 Jun 2015, 04:03 PM
Hi IMF,

In your example there is a new blank Telerik.Reporting.Report instance bound to custom data. Telerik reports are templates which must contain fields from the schema of the assigned data object.

For more details, please check a similar discussion in this forum thread (my first two posts).

Regards,
Stef
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
General Discussions
Asked by
IMF
Top achievements
Rank 1
Answers by
Stef
Telerik team
Share this question
or