Create Report programmatically

2 posts, 0 answers
  1. IMF
    IMF avatar
    17 posts
    Member since:
    Jun 2012

    Posted 15 Jun 2015 Link to this post



    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)
       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;
       public class datos
           public datos()
           public string dato1 ;
           public string dato2 ;
           public string dato3 ;
           public string dato4 ;


    Any idea? Thanks

  2. Stef
    Stef avatar
    3610 posts

    Posted 15 Jun 2015 Link to this post

    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).

    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
Back to Top