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