Hello,
it's possible load a dataset to report in HTML5 Report Viewer from codebehind?
I'm search for this information but i can't find nothing.
In my application i have a aspx with HTML5 Report Viewer and a Report.vb, the report vb contains into a dataset with 3 datatables, but i can't load the data to these dataset.
PD: sorry if my english is a little bad, i speak a little english.
Thank you for your attention and help
11 Answers, 1 is accepted
In general, the purpose of the ObjectDataSource component is to provide data to the report in a declarative manner. The ObjectDataSource.DataSource should be the assembly qualified name or Type of the data access layer (class), where the reporting engine will use System.Reflection to create the instance of the class (by using its default constructor) and to execute its method specified by the ObjectDataSource.DataMember.
The ObjectDataSource and other data source components can load only one DataTable from the wrapped DataSet. If you create a model that exposes relations between the 3 data objects e.g. Entity Framework model, you can use the EntityDataSource component and the data-binding approach from How to Databind to Collection Properties.
Other approach, for updating a report before displaying it, is to use a custom resolver for the Reporting REST service. Please consider the example in this forum post.
Regards,
Stef
Telerik
So i can't not implement this Example with a HTML5 Report?
In my app i have a one dataset with three tables (DatosGenerales, ResumenReferencias, ReferenciasActivas), and the report have one dataobject by each table.
my report is type .vb
Apologies for my english
I'm Get the Error: Value of type 'Telerik.Reporting.InstanceReportSource' cannot be converted to 'Telerik.ReportViewer.Html5.WebForms.ReportSource'. in My app with the example.
this my code:
01.Dim ds As New ReporteHistorialCliente.DatosGeneralesDataTable02. 03.ds.Rows.Add("JHON", "DOE", "0-509-1938", "15/12/2010", "APC BURÓ S.A.", "")04. 05.Dim objDS As New Telerik.Reporting.ObjectDataSource()06. 07.objDS.DataSource = ds08. 09.rptviewerHC.ReportSource = reportSourceThe approach described in How to: Bind to a DataSet suggests how to bind the DataItem to a single DataTable from your DataSet as ObjectdataSourceComponents allows to load only one DataTable from the DataSet.
If this is not suitable in your scenario you can test the approach mentioned in my colleague's post (use EntityDataSource component) or add more DataItems and bind each one to a separate DataTable.
The error message appears because HTML5 WebForms report viewer can only work with TypeReportSource and UriReportSource.
HTML5 Viewer and Reporting REST service use a client-server model where the client sends short string descriptions (messages) to the server and gets content(report) from the server. The viewer(client) can only send a short description of the report (its assembly qualified name) or a path to the file on the server. The string description is interpreted by the service's report resolver which returns a ReportSource object.
When you try to pass report instance (InstanceReportSource) an error will occur as report instances cannot be transferred in a message.
Thus, you need to use TypeReportSource or UriReportSource to set viewer's source, or implement a custom report resolver to handle the resolve process yourself.
Regards,
Katia
Telerik
Hi,
Thanks for your's answers, i can solved my problem
in the load of my aspx i put this code:
reportSource.Identifier = GetType(rptHistCliente).AssemblyQualifiedNamereportSource.Parameters.Add("identClie", identClie)reportSource.Parameters.Add("tipoClie", tipoClie)reportSource.Parameters.Add("usuario", usuario)reportSource.Parameters.Add("identAsoc", identAsoc)Me.rptviewerHC.ReportSource = reportSourceAnd did a class called ReportManager.vb with the methods to fill my rptHistCliente.vb, when the report is loading then databind the methods and fill the tables in the report.
The methods return IEnumerable(Of typeOfClass), example:
Public Function GetDatosGenerales(identClie As String, tipoClie As String) As IEnumerable(Of DatosGenerales)
Thanks for your Help
regards
Por favor si me puedes ayudar un poco Josue,
me sale lo mismo: cant convert Telerik.Reporting.InstanceReportSource to Telerik.ReportViewer.Html5.WebForms.ReportViewer
Si la instacia se crea con Telerik.ReportViewer.Html5.WebForms.ReportViewer, no puedo hacer un bind a los detalles
protected void btnConsultar_Click(object sender, EventArgs e)
{
DataSet ds = new DataSet();
Telerik.Reporting.InstanceReportSource instanceReportSource1 = new Telerik.Reporting.InstanceReportSource();
if (!string.IsNullOrEmpty(txtFecha1.Text) && !string.IsNullOrEmpty(txtFecha2.Text))
{
string periodo = string.Empty, nombre = string.Empty, direccion = string.Empty, telefono = string.Empty, ruc = string.Empty;
string asesor1 = string.Empty, asesor2 = string.Empty, codigo = string.Empty;
string fechaUltPago = string.Empty, montoUltPago = string.Empty, montoPorVencer = string.Empty;
string fechaVencimiento = string.Empty, montoVencido = string.Empty, totalApagar = string.Empty;
ds = clsVariablesNom.objReportesExternos.RepExtEstadoCliente(Convert.ToInt32(Session["idEmpresa"].ToString()), Session["RUC"].ToString(), Convert.ToDateTime(txtFecha1.Text), Convert.ToDateTime(txtFecha2.Text));
if (ds.Tables[1].Rows.Count > 0) {
RepEstadoClienteBrico detalleRep = new RepEstadoClienteBrico();
detalleRep.DataSource = ds.Tables[1];
instanceReportSource1.ReportDocument = detalleRep;
instanceReportSource1.Parameters.Clear();
instanceReportSource1.Parameters.Add(new Telerik.Reporting.Parameter("periodo", periodo));
instanceReportSource1.Parameters.Add(new Telerik.Reporting.Parameter("nombre", nombre));
instanceReportSource1.Parameters.Add(new Telerik.Reporting.Parameter("direccion", direccion));
instanceReportSource1.Parameters.Add(new Telerik.Reporting.Parameter("telefono", telefono));
instanceReportSource1.Parameters.Add(new Telerik.Reporting.Parameter("ruc", ruc));
instanceReportSource1.Parameters.Add(new Telerik.Reporting.Parameter("asesor1", asesor1));
instanceReportSource1.Parameters.Add(new Telerik.Reporting.Parameter("asesor2", asesor2));
instanceReportSource1.Parameters.Add(new Telerik.Reporting.Parameter("codigo", codigo));
instanceReportSource1.Parameters.Add(new Telerik.Reporting.Parameter("fechaUltimoPago", fechaUltPago));
instanceReportSource1.Parameters.Add(new Telerik.Reporting.Parameter("montoUltimoPago", montoUltPago));
instanceReportSource1.Parameters.Add(new Telerik.Reporting.Parameter("montoPorVencer", montoPorVencer));
instanceReportSource1.Parameters.Add(new Telerik.Reporting.Parameter("fechaVencimiento", fechaVencimiento));
instanceReportSource1.Parameters.Add(new Telerik.Reporting.Parameter("montoVencido", montoVencido));
instanceReportSource1.Parameters.Add(new Telerik.Reporting.Parameter("valorApagar", totalApagar));
RvEstadoDet.ReportSource = instanceReportSource1;
RvEstadoDet.RefreshReport();
}
}
else
{
lblStatus.Visible = true;
}
with new Telerik.ReportViewer.Html5.WebForms.ReportViewer cant bind rpt.cs to dataTable
Telerik.Reporting.InstanceReportSource instanceReportSource1 = new Telerik.Reporting.InstanceReportSource();
RepEstadoClienteBrico detalleRep = new RepEstadoClienteBrico();
detalleRep.DataSource = ds.Tables[1]; //from stored procedure
instanceReportSource1.ReportDocument = detalleRep; // data to detail report
instanceReportSource1.Parameters.Clear(); // master parameter (header)
instanceReportSource1.Parameters.Add(new Telerik.Reporting.Parameter("periodo", periodo));
instanceReportSource1.Parameters.Add(new Telerik.Reporting.Parameter("nombre", nombre));
instanceReportSource1.Parameters.Add(new Telerik.Reporting.Parameter("direccion", direccion));
RvEstadoDet.ReportSource = instanceReportSource1; // error cant convert Telerik.Reporting.InstanceReportSource to
//Telerik.ReportViewer.Html5.WebForms.ReportViewer
RvEstadoDet.RefreshReport(); //
Que tal Oscar,
Te comento un poco, ese error no pude solucionarlo puesto que no pude o no encontre como pasar un dataset como tal por medio de parametros. Sin embargo encontre otra vÃa (un poco larga, pero funcional) para poder reflejar la data en el reporte. Lo que puedes hacer es crear un parametro dentro del reporte de tipo String y pasas el dataSet como XML.
Para poder visualizarlo en el reporte debes crear una clase con los campos de la tabla y una lista de los mimsos. Ejemplo:
01.Public Class DatosGenerales02. 03.#Region "Declaraciones"04. Private sNombre As String05. Private sApellido As String06. Private sIdentClie As String07. Private fFecCreacion As String08. Private sUsuario As String09.#End Region10. 11.#Region "Propiedades"12. Public Property Nombre As String13. Get14. Return sNombre15. End Get16. Set(value As String)17. sNombre = value18. End Set19. End Property20. 21. Public Property Apellido As String22. Get23. Return sApellido24. End Get25. Set(value As String)26. sApellido = value27. End Set28. End Property29. 30. Public Property IdentClie As String31. Get32. Return sIdentClie33. End Get34. Set(value As String)35. sIdentClie = value36. End Set37. End Property38. 39. Public Property FecCreacion As String40. Get41. Return fFecCreacion42. End Get43. Set(value As String)44. fFecCreacion = value45. End Set46. End Property47. 48. Public Property Usuario As String49. Get50. Return sUsuario51. End Get52. Set(value As String)53. sUsuario = value54. End Set55. End Property56.#End Region57. 58.#Region "Metodos"59. Public Sub New(Optional nom As String = "", Optional ape As String = "", Optional ident As String = "", Optional fecCre As String = "", Optional user As String = "")60. Nombre = nom61. Apellido = ape62. IdentClie = ident63. FecCreacion = fecCre64. Usuario = user65. End Sub66.#End Region67. 68.End Class69. 70.Public Class ListDatosGenerales71. Inherits List(Of DatosGenerales)72. 73. Public Sub New(dts As DatosGenerales)74. Me.Add(dts)75. End Sub76. 77.End Class
Luego debes crear una clase que tendra un método compartido que sera el que llamaras dentro del reporte.
01.Imports System.Xml02.Imports System.IO03. 04.Public Class ReportManager05. 06. Public Function GetDatosGenerales(xmldt As String) As IEnumerable(Of DatosGenerales)07. Dim infos As New List(Of DatosGenerales)08. Dim datos As DatosGenerales09. Dim dt As New DataTable10. Dim ds As New DataSet11. 12. ds.ReadXml(New XmlTextReader(New StringReader(xmldt)))13. If ds.Tables.Count > 0 Then14. dt = ds.Tables(0)15. 16. For Each dtrow As DataRow In dt.Rows17. datos = New DatosGenerales()18. datos.Nombre = dtrow.Item("NOMBRE")19. datos.Apellido = dtrow.Item("APELLIDO")20. datos.IdentClie = dtrow.Item("IDENT_CLIE")21. datos.FecCreacion = dtrow.Item("FEC_CREACION")22. datos.Usuario = dtrow.Item("USUARIO")23. If infos Is Nothing Then24. infos = New ListDatosGenerales(datos)25. Else26. infos.Add(datos)27. End If28. Next29. Else30. datos = New DatosGenerales()31. infos = New ListDatosGenerales(datos)32. End If33. 34. Return infos35. End Function36. 37.End Class
Luego realizas los siguientes pasos:
- Añadir un ObjectDataSource, este lo podras encontrar en la sección de Telerik Reporting R2...
- Al agregar el Object... te saldrá una lista para seleccionar el tipo del datasource, alli buscas la clase que creastes, en mi caso ReportManager, haces clic en Next
- Te saldrá otro cuadro ahora para elegir de donde se alimentará el datasource, primero seleccionas Choose a datasource member, y en la lista buscas la función que creastes, en mi caso GetDatosGenerales(...) Click a Next
- En el valor del parametro, colocas el parametro que definistes en el reporte que trae el XML y luego le das a finalizar.
Luego en el reporte solo debes agregar una tabla (Puedes usar el Wizard) y asignarle el datasource que acabas de crear y seleccionar las columnas que deseas mostrar.
Por ultimó para setear todo esto al HTML5ReportViewer solo debes usar el siguiente código:
01.Dim reportSource As New Telerik.ReportViewer.Html5.WebForms.ReportSource02. 03.Dim ds as New DataSet04. 05.'ds = (Cargar DataSet)06. 07.reportSource.Identifier = GetType(reporteCreado).AssemblyQualifiedName08.reportSource.Parameters.Add("dsDatosGenerales", ds.GetXml())09. 10.Me.rptviewerHTML5.ReportSource = reportSource
Cualquier consulta a la orden,
Saludos Cordiales
Muchas Gracias la ayuda, el tema es que con la versión anterior del reporting esas lineas de código que puse funcionaban perfectamente, pasaba los parámetros del reporte para el maesto, y el detalle lo cargaba desde un datatable...
Pero en esta verisión de report viewer eso ya no funciona Y LA DECOMUNTACION DE TELERIK SE HA VUELTO POBRE!!
Saludos,
Igualmente cualquier cosa a las ordenes.
I Found a solution,
1._ change into aspx
<%@ Register Assembly="Telerik.ReportViewer.Html5.WebForms, Version=11.0.17.118, Culture=neutral, PublicKeyToken=a9d7983dfcc261be" Namespace="Telerik.ReportViewer.Html5.WebForms" TagPrefix="telerik" %>
TO
<%@ Register Assembly="Telerik.ReportViewer.WebForms, Version=11.0.17.118, Culture=neutral, PublicKeyToken=a9d7983dfcc261be" Namespace="Telerik.ReportViewer.WebForms" TagPrefix="telerik" %>
In version put your telerik version in my case is 11.0.17.118, it can be checked in references.
thats all
My code to do this is
ASPX FILE:
<form id="form1" runat="server">
<div >
<telerik:ReportViewer ID="RvRet" runat="server" Height="700px" Width="100%">
</telerik:ReportViewer>
</div>
</form>
INTO CS FILE :
Telerik.Reporting.InstanceReportSource instanceReportSource1 = new Telerik.Reporting.InstanceReportSource();
rideRet rideRpt = new rideRet(); (rideRet is an report .cs)
rideRpt.DataSource = dsDetalle.Tables[0];
instanceReportSource1.ReportDocument = rideRpt;
instanceReportSource1.Parameters.Clear();
instanceReportSource1.Parameters.Add(new Telerik.Reporting.Parameter("ruc", ruc));
instanceReportSource1.Parameters.Add(new Telerik.Reporting.Parameter("razon", razon));
instanceReportSource1.Parameters.Add(new Telerik.Reporting.Parameter("obligadoContabilidad", obligadoContabilidad));
instanceReportSource1.Parameters.Add(new Telerik.Reporting.Parameter("numcontribuyente", numcontribuyente));
instanceReportSource1.Parameters.Add(new Telerik.Reporting.Parameter("actividadEmpresa", actividadEmpresa));
instanceReportSource1.Parameters.Add(new Telerik.Reporting.Parameter("direc", direc));
instanceReportSource1.Parameters.Add(new Telerik.Reporting.Parameter("DireccionLocal", DireccionLocal));
instanceReportSource1.Parameters.Add(new Telerik.Reporting.Parameter("ciudadLocal", ciudadLocal));
instanceReportSource1.Parameters.Add(new Telerik.Reporting.Parameter("numeroFactura", numeroFactura));
instanceReportSource1.Parameters.Add(new Telerik.Reporting.Parameter("ambiente", ambiente));
instanceReportSource1.Parameters.Add(new Telerik.Reporting.Parameter("tipoEmision", tipoEmision));
instanceReportSource1.Parameters.Add(new Telerik.Reporting.Parameter("claveAcceso", claveAcceso));
instanceReportSource1.Parameters.Add(new Telerik.Reporting.Parameter("fechaEmision", fechaEmision));
instanceReportSource1.Parameters.Add(new Telerik.Reporting.Parameter("razonSocialComprador", razonSocialComprador));
instanceReportSource1.Parameters.Add(new Telerik.Reporting.Parameter("identificacionComprador", identificacionComprador));
instanceReportSource1.Parameters.Add(new Telerik.Reporting.Parameter("campoAdicional", campoAdicional));
instanceReportSource1.Parameters.Add(new Telerik.Reporting.Parameter("totalSinImpuestos", totalSinImpuestos));
instanceReportSource1.Parameters.Add(new Telerik.Reporting.Parameter("totalDescuento", totalDescuento));
instanceReportSource1.Parameters.Add(new Telerik.Reporting.Parameter("importeTotal", importeTotal));
instanceReportSource1.Parameters.Add(new Telerik.Reporting.Parameter("subTotalIva0", subTotalIva0));
instanceReportSource1.Parameters.Add(new Telerik.Reporting.Parameter("subTotalIva12", subTotalIva12));
instanceReportSource1.Parameters.Add(new Telerik.Reporting.Parameter("valorIVA12", valorIVA12));
instanceReportSource1.Parameters.Add(new Telerik.Reporting.Parameter("numeroAutorizacion", numeroAutorizacion));
instanceReportSource1.Parameters.Add(new Telerik.Reporting.Parameter("fechaAutorizacion", fechaAutorizacion));
if (dtB.Rows[0][1].ToString() == "9")
{
instanceReportSource1.Parameters.Add(new Telerik.Reporting.Parameter("periodoFiscal", periodoFiscal));
}
RvRet.ReportSource = instanceReportSource1;
RvRet.RefreshReport();
thats all, u can use report cs, for header and footer report use "=parameters.ruc", for detail report us "=fields.ruc" field came form datatable and my datatable were populated from stored procedure....
In html5 vierwer cant do that.... is an other achitecture.! so my solutions is using viewer webform.
Hola Josue y Oscar, espero esten bien.
Soy nuevo utilizando Telerik Reporting, y estoy utilizando este hilo para lograr enlazar mi codigo de c# y enviarle la informacion de mi DataSet hacia el reporte.
Ya realice los pasos que mencion Josue, y el diseñador de reportes si me reconoce la dll y la clase para generar el ObjectDataSource... pero cuando corro mi programa me muestra el siguiente error:
An error has occurred while processing Table 'table1':
The assembly "Telerik_test_webforms, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
is not permitted to be used by an ObjectDataSource component. Please include it in an
AssemblyReferences element in the Telerik.Reporting configuration section of your
application configuration file
Logro comprender que el problema esta en alguna configuracion o algo por el estilo... en el archivo Telerik.ReportDesigner.exe.config ya agregue la linea : <add name="Telerik_test_webforms" version="1.0.0.0" culture="neutral" publicKeyToken ="null" />
Pero sigue sin funcionar.
No se si deba agregar tambien algo en el web.config o algo por el estilo.
Espero me puedan ayudar.
Muchas gracias.
Hi Gregorio,
Please, note that the official language for communication in the Telerik Support system is English. I used Google Translator to translate your message. Here is the produced English text I will address:
I'm new to Telerik Reporting, and I'm using this thread to hook up my C# code and send the information from my DataSet to the report.
I have already carried out the steps that Josue mentioned, and the report designer does recognize the dll and the class to generate the ObjectDataSource... but when I run my program it shows me the following error:
An error has occurred while processing Table 'table1':
The assembly "Telerik_test_webforms, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
is not permitted to be used by an ObjectDataSource component. Please include it in an
AssemblyReferences element in the Telerik.Reporting configuration section of your
application configuration file
I managed to understand that the problem is in some configuration or something like that... in the file Telerik.ReportDesigner.exe.config I already added the line: <add name="Telerik_test_webforms" version="1.0.0.0" culture="neutral " publicKeyToken ="null" />
But it still doesn't work.
I don't know if I should also add something in the web.config or something like that.
Que tal Gregorio,
Te recomiendo que dentro del mismo proyecto donde estás colocando el reporte agregues la referencia o crees una clase y le colocas el método que necesitas, uno es para DataTable y el Otro para DataSet:
public static System.Data.DataTable XmlToDataTable(string Xml)
{
System.Data.DataTable dtResult = new System.Data.DataTable();
System.Data.DataSet ds = new System.Data.DataSet();
ds.ReadXml(new System.IO.StringReader(Xml));
if (ds.Tables.Count > 0)
dtResult = ds.Tables[0];
return dtResult;
}
public static System.Data.DataSet XmlToDataSet(string Xml)
{
System.Data.DataSet ds = new System.Data.DataSet();
ds.ReadXml(new System.IO.StringReader(Xml), System.Data.XmlReadMode.InferSchema);
return ds;
}y para enviar el parámetro en forma de XML desde el código, utilizas alguna de estas funciones según sea tu caso:
public static string DataTableToXml(System.Data.DataTable dt, string TableName = "DATA_TABLE")
{
string result = string.Empty;
if (string.IsNullOrEmpty(dt.TableName))
dt.TableName = TableName;
System.IO.StringWriter sw = new System.IO.StringWriter();
dt.WriteXml(sw, System.Data.XmlWriteMode.WriteSchema);
result = sw.ToString();
return result;
}
public static string DataSetToXml(System.Data.DataSet ds)
{
string FinalResult = string.Empty;
string result = string.Empty;
System.Text.StringBuilder str = new System.Text.StringBuilder();
foreach (System.Data.DataTable dt in ds.Tables)
{
System.IO.StringWriter sw = new System.IO.StringWriter();
dt.WriteXml(sw);
str.Append(sw);
}
FinalResult = str.ToString();
return FinalResult;
}En tu código serÃa algo parecido a esto:
System.Data.DataTable dtInfo = GetDataReportInfo();
reportSource.Parameters.Add("XmlData", DataTableToXml(dtInfo));Nota: Esto solo lo he probado en los reportes de tipo dll. si estas usando los RLDX intenta colocar la dll Telerik_test_webforms en el bin de la carpeta donde lo estes ejecutando
Thank you so much todor.
Gracias Josue, ya encontre la solucion, de hecho, me fueron muy utiles tus apuntes antiguos en este mismo hilo, muchas gracias. Lo que me faltaba era agregar los asemblies tambien en el webconfig del proyecto.
