HTML5 Report Viewer load DataSet on codebehind

12 posts, 0 answers
  1. Josue
    Josue avatar
    9 posts
    Member since:
    Jan 2016

    Posted 30 May 2016 Link to this post


    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

  2. Stef
    Stef avatar
    3611 posts

    Posted 31 May 2016 Link to this post

    Hi Josue,

    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.

    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
  3. Josue
    Josue avatar
    9 posts
    Member since:
    Jan 2016

    Posted 31 May 2016 in reply to Stef Link to this post

    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

  4. Josue
    Josue avatar
    9 posts
    Member since:
    Jan 2016

    Posted 31 May 2016 in reply to Josue Link to this post

    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.DatosGeneralesDataTable
    03.ds.Rows.Add("JHON", "DOE", "0-509-1938", "15/12/2010", "APC BURÓ S.A.", "")
    05.Dim objDS As New Telerik.Reporting.ObjectDataSource()
    07.objDS.DataSource = ds
    09.rptviewerHC.ReportSource = reportSource
  5. Josue
    Josue avatar
    9 posts
    Member since:
    Jan 2016

    Posted 31 May 2016 Link to this post

    Why i Can't edit or delete my answers, i publish the code with a error... and need edit de answer.
  6. Katia
    Katia avatar
    566 posts

    Posted 03 Jun 2016 Link to this post

    Hi Josue,

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

    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
  7. Josue
    Josue avatar
    9 posts
    Member since:
    Jan 2016

    Posted 03 Jun 2016 Link to this post


    Thanks for your's answers, i can solved my problem

    in the load of my aspx i put this code:

    reportSource.Identifier = GetType(rptHistCliente).AssemblyQualifiedName
    reportSource.Parameters.Add("identClie", identClie)
    reportSource.Parameters.Add("tipoClie", tipoClie)
    reportSource.Parameters.Add("usuario", usuario)
    reportSource.Parameters.Add("identAsoc", identAsoc)
    Me.rptviewerHC.ReportSource = reportSource

    And 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


  8. Oscar
    Oscar avatar
    4 posts
    Member since:
    Oct 2013

    Posted 17 Mar in reply to Josue Link to this post

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

                    lblStatus.Visible = true;

  9. Oscar
    Oscar avatar
    4 posts
    Member since:
    Oct 2013

    Posted 17 Mar Link to this post

    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  

                        RvEstadoDet.RefreshReport(); //  

  10. Josue
    Josue avatar
    9 posts
    Member since:
    Jan 2016

    Posted 17 Mar in reply to Oscar Link to this post

    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 DatosGenerales
    03.#Region "Declaraciones"
    04.    Private sNombre As String
    05.    Private sApellido As String
    06.    Private sIdentClie As String
    07.    Private fFecCreacion As String
    08.    Private sUsuario As String
    09.#End Region
    11.#Region "Propiedades"
    12.    Public Property Nombre As String
    13.        Get
    14.            Return sNombre
    15.        End Get
    16.        Set(value As String)
    17.            sNombre = value
    18.        End Set
    19.    End Property
    21.    Public Property Apellido As String
    22.        Get
    23.            Return sApellido
    24.        End Get
    25.        Set(value As String)
    26.            sApellido = value
    27.        End Set
    28.    End Property
    30.    Public Property IdentClie As String
    31.        Get
    32.            Return sIdentClie
    33.        End Get
    34.        Set(value As String)
    35.            sIdentClie = value
    36.        End Set
    37.    End Property
    39.    Public Property FecCreacion As String
    40.        Get
    41.            Return fFecCreacion
    42.        End Get
    43.        Set(value As String)
    44.            fFecCreacion = value
    45.        End Set
    46.    End Property
    48.    Public Property Usuario As String
    49.        Get
    50.            Return sUsuario
    51.        End Get
    52.        Set(value As String)
    53.            sUsuario = value
    54.        End Set
    55.    End Property
    56.#End Region
    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 = nom
    61.        Apellido = ape
    62.        IdentClie = ident
    63.        FecCreacion = fecCre
    64.        Usuario = user
    65.    End Sub
    66.#End Region
    68.End Class
    70.Public Class ListDatosGenerales
    71.    Inherits List(Of DatosGenerales)
    73.    Public Sub New(dts As DatosGenerales)
    74.        Me.Add(dts)
    75.    End Sub
    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.Xml
    02.Imports System.IO
    04.Public Class ReportManager
    06.    Public Function GetDatosGenerales(xmldt As String) As IEnumerable(Of DatosGenerales)
    07.        Dim infos As New List(Of DatosGenerales)
    08.        Dim datos As DatosGenerales
    09.        Dim dt As New DataTable
    10.        Dim ds As New DataSet
    12.        ds.ReadXml(New XmlTextReader(New StringReader(xmldt)))
    13.        If ds.Tables.Count > 0 Then
    14.            dt = ds.Tables(0)
    16.            For Each dtrow As DataRow In dt.Rows
    17.                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 Then
    24.                    infos = New ListDatosGenerales(datos)
    25.                Else
    26.                    infos.Add(datos)
    27.                End If
    28.            Next
    29.        Else
    30.            datos = New DatosGenerales()
    31.            infos = New ListDatosGenerales(datos)
    32.        End If
    34.        Return infos
    35.    End Function
    37.End Class


    Luego realizas los siguientes pasos:

    1. Añadir un ObjectDataSource, este lo podras encontrar en la sección de Telerik Reporting R2...
    2. 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
    3. 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
    4. 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.ReportSource
    03.Dim ds as New DataSet
    05.'ds = (Cargar DataSet)
    07.reportSource.Identifier = GetType(reporteCreado).AssemblyQualifiedName
    08.reportSource.Parameters.Add("dsDatosGenerales", ds.GetXml())
    10.Me.rptviewerHTML5.ReportSource = reportSource


    Cualquier consulta a la orden,


    Saludos Cordiales



  11. Oscar
    Oscar avatar
    4 posts
    Member since:
    Oct 2013

    Posted 17 Mar in reply to Josue Link to this post

    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!!


    Igualmente cualquier cosa a las ordenes.

  12. Oscar
    Oscar avatar
    4 posts
    Member since:
    Oct 2013

    Posted 24 Mar in reply to Oscar Link to this post

    I Found a solution,

    1._ change into aspx

    <%@ Register Assembly="Telerik.ReportViewer.Html5.WebForms, Version=, Culture=neutral, PublicKeyToken=a9d7983dfcc261be" Namespace="Telerik.ReportViewer.Html5.WebForms" TagPrefix="telerik" %>


    <%@ Register Assembly="Telerik.ReportViewer.WebForms, Version=, Culture=neutral, PublicKeyToken=a9d7983dfcc261be" Namespace="Telerik.ReportViewer.WebForms" TagPrefix="telerik" %>

    In version put your telerik version in my case is, it can be checked in references.

    thats all


    My code to do this is



    <form id="form1" runat="server">
        <div >
            <telerik:ReportViewer ID="RvRet" runat="server" Height="700px" Width="100%">



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


    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.



Back to Top