This is a migrated thread and some comments may be shown as answers.

Telerik Report in asp.net website

7 Answers 376 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Felice
Top achievements
Rank 1
Felice asked on 11 Oct 2013, 05:59 AM
I have an asp.net website based on Radgrids and a DB.
The Radgrids are mostly used to post data to the db. I would like to introduce some page containing  Telerik Reporting to show the data from the db in specific formats. 
I have created a report with the stand alone tool and checked if it is working.
I have added a report viewer and a script manager to the web page.
How do I connect the report to the report viewer now?
Here is where I am stuck!


I am not a professional coder but I learn quickly. Some example and reference could help me to come right on this.


Thanks for supporting.

7 Answers, 1 is accepted

Sort by
0
Stef
Telerik team
answered on 11 Oct 2013, 02:34 PM
Hello Felice,

The created XML report definition (trdx file) can be displayed in the ASP.NET ReportViewer control using a report source object:
  • UriReportSource - the trdx file can be directly displayed by setting the UriReportSource.Uri to the trdx location;
  • InstanceReportSource - the trdx file can be deserialized and modified on the server if needed, and then displayed with an InstanceReportSource object;
  • XmlReportSource - the trdx file content can be read as a string and set to the XmlReportSource.Xml

Notice you should add any connection strings used in the report into the web.config file.

Regards,
Stef
Telerik

Have you tried the new visualization options in Telerik Reporting Q2 2013? You can get them from your account.

0
Felice
Top achievements
Rank 1
answered on 11 Oct 2013, 05:25 PM
Hi Stef,
Thanks a lot for your patience. As I mentioned before I am not a professional coder and I was tired to be dependent on few developers for each single change I wont to introduce to my website. May be I had a couple of ugly experiences. I know that there are also good developers around.
However, finally I succeeded in building up a class library with couple of reports in it connected to the db and showing up the data in the format I decided.  I had no problem to add the report to a WinForm.
I battled a bit when I tried to add the report to a web application and thereafter to a website but finally I won. I added, in both cases,  a Telerik Report Viewer and I instantiated the library and report as following:

protected void Page_Load(object sender, EventArgs e)
        {
            ReportViewer1.Report = new MyClassRep1.Report1();
        }
I would appreciate if you can confirm me that this is the correct way to do it or recommend me how should I do it. I have not tested it on the hosting server however, at least is working on my machine.

Going back to my original problem. I had a lot of troubles to do the above in an existing website project. Several controls were not displayed in the toolbox and not having previous experiences with your controls I went mad before I picked up that  the project giving me troubles was made with a very old version of Telerik controls. What sounds strange to me is that I have updated that project to the latest version but still when I open that particular updated solution the Telerik Reporting tools disappear from the tool box. I have attached a couple of pics from two instances of VS20012 showing a new testing solution and the old one with the toolbox and version circled in red.
How can I sort out the problem on the old project updated which is not showing the Reporting tools? 

Sorry for the long story. I am nearly there.

Kind regards
Felice
0
Felice
Top achievements
Rank 1
answered on 11 Oct 2013, 06:07 PM
Hi Stef,

I solved the problem about the Reporting tools not showing in the toolbox.
Actually that project was on framework 3.5, after updating it to framework 4.0 the reporting tools shows up.
Still please give me an answer for the other question.

Thanks
Felice
0
David
Top achievements
Rank 1
Iron
Veteran
Iron
answered on 11 Oct 2013, 08:27 PM
Your problems sound like those I have experienced.  While I love the Telerik suite of tools the only negative I found with their products is the constant disappearing of their code from the Studio's toolbox pallet within VS 2012.  In fairness to Telerik I suspect the real problem is Microsofts fault and not specifically Telerik's.  Yes, a workaround would be nice by Telerik however I have yet to see a permanent one.

First, the easy solution:  Have you discovered Telerik's Control Panel?  The control panel is a tool developed by Telerik which automates the download and installation of the various Telerik products.  With this tool I have had 100% success with updates.  WIthout this tool I have had nothing but headaches.  This tool uninstalls the prior version and then installs the new version.  It then rebuilds the toolbox cache using by VS 2012.  Not everyone does all of these actions when updates are retrieved manually.  use the tool is my first suggestion.

My second suggestion is to use the "Launch Toolbox Configurator" which resides in the Telerik product menus.  It does not exist in the report menu but you should be able to get to it via one of the menu's.  The toolbox configurator controls the .DLL's which are loaded into memory and end up displaying data within the developer toolbox.  You can add/remove anything you want.  Using this tool you can force the Report tools to reappear in your toolbox.

My third suggestion:  Do a web search to find the hidden toolbox cache files located in your profile.  I have had situations where I have had to remove the related files which then forces the VS2012 product to rebuild its indexes on the next load of the product.  While this is insanely slow it actually works.  The path you need is something like "%USERPROFILE%\appdata\local\microsoft\visualstudio\11.0\".  (assuming VS 2012)  You need to remove the files entitled "toolbox*.tbd"  These files and paths are all hidden so you will have to do some fancy actions to see things.  Be careful as this is the brute force solution.


0
Felice
Top achievements
Rank 1
answered on 12 Oct 2013, 05:38 AM
Hi David,
thanks for sharing with me your experience about the tools disappearing.
In my case I solved the problem upgrading the project that was giving me troubles from .net framework 3.5 to 4.0 and suddenly the tools appeared in the toolbox. I think that in this particular case was a limitation of the 3.5 framework feature  in consuming the Telerik libraries.

I am not sure if you can help on the other question in my post.
It is about Reporting in asp.net website.
Following this tutorial, I have simply added a line of code to instantiate the report in my page instead of the recommended method.
This is what I have done:
protected void Page_Load(object sender, EventArgs e)
    {
 
        if (!IsPostBack)
        
            ReportViewer1.Report = new MyClassRep1.Report1();
            ReportViewer1.RefreshReport();
        }
    }
Would this be safe enough to render the report in a website?
This is the first time I use this tool.
Thanks,
Felice
0
Accepted
David
Top achievements
Rank 1
Iron
Veteran
Iron
answered on 12 Oct 2013, 04:39 PM
At its most basic sense you have what is required.    I have site with dozens of reports.   As such I have taken the steps a bit further.

I created a "generic" webpage which has the sole purpose of displaying a report.  While this sounds simple, what happens if you have one report which is in landscape mode and the next one is in portrait mode?  I prefer to have my reports consume all available space when displayed on the screen.

As such here the bulk of the HTML markup:

<html xmlns="http://www.w3.org/1999/xhtml" id="html">
<head id="Head1" runat="server">
    <title id="RPTNAME"></title>
    <style type="text/css">  
    form#form1, div#content
    {
        height: 100%;
    }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div id="content">
        <telerik:ReportViewer ID="rptViewer" runat="server" height="100%"
            onprerender="RptViewerPreRender">
        </telerik:ReportViewer>
    </div>
    </form>
</body>
</html>

Notice that I also wired up the pre-render event?  This was necessary to set the height/width of the page.  Here is a portion of the C# logic you would need to implement the "generic" "ViewReport.aspx".  

/// <summary>
/// A property which is used to set the Height of the reports viewer control
/// </summary>
public System.Web.UI.WebControls.Unit PageHeight { get; set; }
/// <summary>
/// A property which is used to set the width of the reports viewer control
/// </summary>
public System.Web.UI.WebControls.Unit PageWidth { get; set; }
 
 
/// <summary>
/// A event which is used to configure the page for use
/// </summary>
/// <param name="sender">not used</param>
/// <param name="e">not used</param>
protected void Page_Load(object sender, EventArgs e)
{
        try
        {
            if (this.IsPostBack == false)
            {
                String report = Request["REPORT"];
                if (String.IsNullOrWhiteSpace(report) == false)
                {
                    report = report.ToUpper();
                    switch (report)
                    {
                        case "REPORT1":
                            this.Title = "Title for Report 1";
                            // call whatever logic is required to create a report object (You must write this of course)
                            SetReportViewer(CreateReportOne());
                            break;
                        case "REPORT2":
                            this.Title = "Title for Report 2";
                            // call whatever logic is required to create a report object  (You must write this of course)
                            SetReportViewer(CreateReportTwo());
                            break;
                        default:
                            break;
                    }
                }
            }
        }
        catch (Exception)
        {
                // you should have better error handling than this
    throw;
        }
}
 
/// <summary>
/// A event which is used to set the controls height/width on creation
/// </summary>
/// <param name="sender">not used</param>
/// <param name="e">not used</param>
protected void RptViewerPreRender(object sender, EventArgs e)
{
    rptViewer.Height = PageHeight;
    rptViewer.Width = PageWidth;
}
 
/// <summary>
/// A method which is used to set the viewer to the specified report and adjust for landscape/portrait modes
/// </summary>
/// <param name="report">The report to bind to the viewer</param>
public void SetReportViewer(IReportDocument report)
{
    try
    {
        SetReportViewMode(report);
        InstanceReportSource irs = new InstanceReportSource();
        irs.ReportDocument = report;
        rptViewer.ReportSource = irs;
        if (report != null)
        {
            rptViewer.RefreshReport();
        }
    }
    catch (Exception)
    {
        // you should have better error handling than this
throw;
    }
}
 
/// <summary>
/// A method which sets the specified report into either Landscape or Portrait mode
/// </summary>
/// <param name="report">The report to set</param>
private void SetReportViewMode(IReportDocument report)
{
    try
    {
        if (report.PageSettings.Landscape == true)
        {
            SetLandscapeMode();
        }
        else
        {
            SetPortraitMode();
        }
    }
    catch (Exception)
    {
        // you should have better error handling than this
throw;
    }
}
 
/// <summary>
/// A method which sets the viewer to portrait mode
/// </summary>
private void SetPortraitMode()
{
    try
    {
        PageHeight = new System.Web.UI.WebControls.Unit(11.0, System.Web.UI.WebControls.UnitType.Inch);
        PageWidth = new System.Web.UI.WebControls.Unit(8.5, System.Web.UI.WebControls.UnitType.Inch);
    }
    catch (Exception ex)
    {
        // you should have better error handling than this
throw;
    }
}
 
/// <summary>
/// A method which sets the viewer into landscape mode
/// </summary>
private void SetLandscapeMode()
{
    try
    {
        PageHeight = new System.Web.UI.WebControls.Unit(8.5, System.Web.UI.WebControls.UnitType.Inch);
        PageWidth = new System.Web.UI.WebControls.Unit(11.0, System.Web.UI.WebControls.UnitType.Inch);
    }
    catch (Exception)
    {
        // you should have better error handling than this
throw;
    }
}


If you use such logic then your application could use URL's such as "viewpage.aspx?REPORT=REPORT1" or "viewpage.aspx?REPORT=REPORT2".  This keeps your logic separated and somewhat more generic.

Hope you find this useful.

0
Felice
Top achievements
Rank 1
answered on 12 Oct 2013, 05:11 PM
Dear David,
thanks a million for all the references you have given me. This will help me a lot.
Thanks,
Felice
Tags
General Discussions
Asked by
Felice
Top achievements
Rank 1
Answers by
Stef
Telerik team
Felice
Top achievements
Rank 1
David
Top achievements
Rank 1
Iron
Veteran
Iron
Share this question
or