Home / Community & Support / Knowledge Base / Telerik Reporting / General, Installation / Handle html in reports when you’re in the context of a web page only

Handle html in reports when you’re in the context of a web page only

Article Info

Rating: 4

Article information

Article relates to

 Telerik Reporting

Created by

 Steve

Last modified

 July 3rd 2008

Last modified by

 Steve


HOW-TO
Handle and render html in reports when using Telerik Reports in web.

DESCRIPTION
Currently Telerik Reporting does not operate with HTML content. Exception is when the report is rendered in HTML because the browser that usually displays the report, handles the HTML itself. Unfortunately the rest of the supported formats - Image (GDI), PDF, XLS, RTF do not support HTML out of the box and we're still looking for possible ways to implement our own HTML rendering in most of the supported export formats.

SOLUTION
Since currently html tags would be displayed "as is" in all other supported formats except html, it is good idea to differentiate between the format you're in. The best way to do that is using the System.Web.HttpContext class and check if you're "rendered" in html or in anything else and based on that check change the rendered data. Here is a sample code that changes the textbox text based on whether you're in a web browser or in win app:
C#

private void nameDataTextBox_ItemDataBound(object sender, EventArgs e)          
   {          
      HttpContext context = System.Web.HttpContext.Current;          
      if (context != null)          
        {          
           string opType = context.Request.QueryString["optype"];          
           string exportFormat = context.Request.QueryString["ExportFormat"];          
             if ((opType == "Report") || ((opType == "Export") && (exportFormat == "MHTML")))          
             {          
               Processing.TextBox txt = sender as Processing.TextBox;          
                 if (txt != null)          
                  {          
                   txt.Text = String.Format("<a href='http://www.google.com/search?q={0}' type='text/html'>Check in Google</a>", txt.Text);          
                  }          
             }          
        }          
   } 

VB.NET:

Private Sub nameDataTextBox_ItemDataBound(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles nameDataTextBox.ItemDataBound    
        Dim context As HttpContext = System.Web.HttpContext.Current    
        If context IsNot Nothing Then    
            Dim opType As String = context.Request.QueryString("optype")    
            Dim exportFormat As String = context.Request.QueryString("ExportFormat")    
            If (opType = "Report"OrElse ((opType = "Export"AndAlso (exportFormat = "MHTML")) Then    
                Dim txt As Processing.TextBox = TryCast(sender, Processing.TextBox)    
                If txt IsNot Nothing Then    
                    txt.Text = [String].Format("<a href='http://www.google.com/search?q={0}' type='text/html'>Check in Google</a>", txt.Text)    
                End If    
            End If    
        End If    
    End Sub 


and here is how it looks in Web ReportViewer:
 Web ReportViewer

and Win ReportViewer:

Win Report Viewer

Exporting to formats that do not support html would export the data without the html tags included. Sample projects in C# and VB.NET have been attached for your convenience.

Comments

If you'd like to comment on this KB article, please, send us a Support Ticket.
Thank you!

Please Sign In to rate this article.