Can't Convert Earlier Version of Telerik Report to HTML 5

2 posts, 0 answers
  1. gc_0620
    gc_0620 avatar
    246 posts
    Member since:
    Feb 2008

    Posted 28 Nov 2018 Link to this post

    I have a web app that was developed in earlier Telerik report viewer.

    I am using Stored Procedure to Populate the report data source as well as Session Variable to filter the Report Data. Seems can't able to work in HTML5 Format. Below are my Web Form and code file. Any Help will be appreciated for a sample application or link . Thanks

    gc_0620

    protected void Page_Load(object sender, EventArgs e)
        {
     
            if (!IsPostBack)
            {
                // this.ReportViewer1.RefreshReport();
               // Response.AppendHeader("X-UA-Compatible", "IE=edge");
                string[] retrievedLocations = (string[])Session["FacilityData"];
                Array.Sort(retrievedLocations);
     
                for (int i = 0; i < retrievedLocations.Length; i++)
                {
                    if (i == 0)
                    {
                        location = "" + retrievedLocations[i] + ","; // Add a comma if data already exists
                    }
                    else
                    {
                        location += "" + retrievedLocations[i] + ",";
                    }
                }
     
                location = location.Substring(0, location.Length - 1);
     
     
                Reports.Intake_Coordinator_CM_Assignments myReport = new Reports.Intake_Coordinator_CM_Assignments();
                string sql = "[dbo].[Intake_Coordinator_Report_Source]";
                SqlCommand command = new SqlCommand(sql, new SqlConnection(connectionString));
                command.CommandType = CommandType.StoredProcedure;
     
                var sqlparam = new SqlParameter("@location", SqlDbType.NVarChar);
                sqlparam.Value = location; //outer value
                command.Parameters.Add(sqlparam);
     
                 
                DataSet dataSet = new DataSet();
                adapter.Fill(dataSet);
                myReport.DataSource = dataSet.Tables[0];//outer data source
                string Tempstr = command.CommandText.ToString();
                string Tempstr1 = Tempstr;
                var reportSourceInstance1 = new InstanceReportSource() { ReportDocument = myReport };
                ReportViewer1.ReportSource = reportSourceInstance1;
        }
     
      }
     
    ________________________
     
    Web Form.
     
    <%@ Page Title="Intake CM Assignments Report" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
    CodeFile="Intake_Coordinator_CM_Assignments_Report.aspx.cs"
    Inherits="Intake_Coordinator_CM_Assignments_Report" %>
     
     
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
     
    <%@ Register Assembly="Telerik.ReportViewer.WebForms, Version=12.1.18.620, Culture=neutral, PublicKeyToken=a9d7983dfcc261be" Namespace="Telerik.ReportViewer.WebForms" TagPrefix="telerik" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
        
        <link href="styles.css" rel="stylesheet" type="text/css" />
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
        
        <asp:Panel runat="server" ID="Panel2" Visible="True" CssClass="form_header_label">
            <asp:Label ID="Label1" runat="server" Text="Intake YTD Status" Font-Size="14px" Font-Bold="true"
                Font-Underline="True"></asp:Label>
        </asp:Panel>
         <br />
        <br />
        <br />
        <div>
            <telerik:ReportViewer ID="ReportViewer1" runat="server" Style="border: 1px solid #ccc;"
                Height="650px" Width="95%" Skin="Office2007">
             <typereportsource
                 
                typename="Reports.Intake_Coordinator_CM_Assignments, Reports, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"></typereportsource>
             </telerik:ReportViewer>
        </div>
    </asp:Content>

     

  2. Silviya
    Admin
    Silviya avatar
    422 posts

    Posted 03 Dec 2018 Link to this post

    Hello,

    Details how to start using the HTML5 Viewer or any of its wrappers (WebForms and MVC) are available in Migrate to the HTML5 Viewer from the old ASP.NET WebForms ReportViewer control.
    The article include links to help resources describing the Vs item templates which can be used.

    A short notes how the viewer works:
    1. The viewer has a client-side ReportSource, from which we extract the string description of the report (relative path to a TRDP|TRDX file), the assembly qualified name of a report class (<namespace>.<report_class>, <assembly_name>) or custom string (almost anything can be included with respect to REST limitations for used characters and size of the message).
    2. The reports string description is submitted to the server and it is handled by the Reporting REST service's Resolver. The service's default resolvers can handle a relative path to a TRDP|TRDX files or an assembly qualified name of a report class. Anything else requires you to create a custom resolver that returns a server-side ReportSource object on its own.
    3. Once the Report resolver returns the server-side ReportSource object, the viewer submits the Parameters collection of its client-side ReportSource. This Parameters collection is applied as the server-side's ReportSource.Parameters collection.
    4. Next, the reporting engine starts processing the report, means the report events fire, expressions are evaluated. At that moment the server-side ReportSource.Parameters collection is mapped to the report's ReportParameters collection - where Name properties (case sensitive) are the same, values are set for the report parameters.
    5. Finally, the report is rendered and paged in the requested format (HTML for web preview, PDF for export and etc.), and the content id returned to the client(viewer).

    Having the above into account, if you want to modify a report at run-time, e.g. change connection strings in the report, you will have to create an InstanceReportSource on the server where the Reporting REST service is running - How to display a report via InstanceReportSource in the HTML5 Viewer.

    If the data has to be filtered, in the report you can use a parameterized SQL query e.g. "Select * from Departments where DepartmentId > @SQLdepId". The SQL parameter can be mapped to a report parameter on configuring the SqlDataSource component (step 4). For more details, check Using Parameters with the SqlDataSource component.
    Report parameters can be updated through the viewer's ReportSource.Parameters collection which is mapped by key (parameter Name) to the report's ReportParameters collection.

    On configuring the SqlDataSource you can also select to save the connection string by name. Then the connection string will be obtained by name which is searched in the web.config file under connectionStrings.

    If you still want to modify the report as in your code snippet, you can use a custom resolver. Please consider this example. Note that the Reporting REST service is a WebAPi controller and you will have to "enable" the ASP.NET Session for WebAPI controllers in order to use session variables.

    At the end, you might need to use the Telerik.ReportViewer.Html5.WebForms instead of Telerik.ReportViewer.WebForms and review How to: Set ReportSource for Report Viewers (for HTML5 ASP.NET WebForms). Example of setting the client-side ReportSource via web form page:
    <form runat="server">
        <telerik:ReportViewer Width="" Height=""
            ID="reportViewer1"
            runat="server">
            <ReportSource
                IdentifierType="TypeReportSource"
                Identifier="Telerik.Reporting.Examples.CSharp.ReportCatalog, CSharp.ReportLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
                <Parameters>
                    <telerik:Parameter Name="Parameter1" Value="123" />
                </Parameters>
            </ReportSource>
        </telerik:ReportViewer>
    </form>

    Regards,
    Silviya
    Progress 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
Back to Top