Rendering HTML in Reporting Services Text Boxes in SQL Server 2008

Some time back, I posted about how to do this. Well by the time we got to RTM, this had changed.

There isn't a "create placeholder" option when you right-click a cell any more.

When you drag a field into a cell, it creates a placeholder that contains the field. If you right-click the placeholder that was added, you'll see an option to edit the Placeholder Properties. What threw me for a while was that if you right-click the cell, you won't see this option. Turns out you have to right-click the field-name within the cell, not the blank area beside the name within the cell. Thanks to my colleague Jessica Moss for helping me find it.

This really isn't very good UI work in the report designer. It's quite counter-intuitive and different to how cell selection, etc. works in other products like Excel.

15 thoughts on “Rendering HTML in Reporting Services Text Boxes in SQL Server 2008”

  1. I am having the same problem that is one of my fields in the report is outputing html I was wondering if there is any way you can do the same in SQL Reporting 2005?

  2. @john, Linda, Ron: You can not achive with default properties/functionalities of SSRS 2005.
    You can write a custom code in vb that interpret html into text.(Report Properties –> Code).
    That's all you can do in SSRS 2005. Good luck.

  3. I am trying to do this in 2008 with the italics, but it only prints the tags in plain text.  I have it marked for HTML in the placeholder.  Is there something I am missing?

  4. Man, this kept me from progressing for at least 3 or 4 hours. What an obscurely integrated feature. Thanks for the tip.

  5. Alternative method to display HTML fields in reports
    If you have reduced set of HTML tags in your dataset fields (like tables, formatting, inline tags), you can try JS-injection.
    It is used to convert an HTML-encoded field, that's generated by Report Manager into actual tags after page is loaded, but before rendered.
    Injection use Ajax Client Life-Cycle Events (http://msdn.microsoft.com/en-us/library/bb386417.aspx).
    You need to modify script Install Dir\Reporting Services\ReportManager\js\ReportingServices.js by add this function at the beginning:
    ///////////////////////////////////////////////////////////
    //SSRS 2008 R2 HTML tags injection before render report
    /////////////////////////////////////////////////////////////
    function pageLoad() {
    var toDecode = document.getElementsByTagName("div");
    for (var i = 0; i < toDecode.length; ++i){
        if(toDecode[i].innerHTML.indexOf("&lt;table ") == 0){
            //alert(toDecode[i].innerText);
            Decoded = toDecode[i].innerText || toDecode[i].textContent; //IE, Opera vs FF
            toDecode[i].innerHTML = Decoded;
        }
    }
    }
    ///////////////////////////////////////////////////////////
    //End injection
    ///////////////////////////////////////////////////////////
    Code gets all DIV elements in loaded page
    Check for each DIV if encoded tags ("&;;lt;table" in this case) is present at position=0
    Swap innerText to innerHTML property and then render page
    You can modify step 2 to check for special tag, if you sure, that it is always at position=0 in your field.
    If tags with CSS classes or ids, you can modify this CSS: Install Dir\Reporting Services\ReportManager\Styles\ReportingServices.css
    Also, you need to set placeholder property "General\Markup type" to "None – Plain text only" in all fields, that you want to convert.
    Next possible modifications are:
    If your fields have non-predefined structure, you can add prefix in placeholder value like this: ="HTMLInject:"+Fields!Field1.Value
    And then modify injection script to seek at position=0 this prefix: if(toDecode[i].innerHTML.indexOf("HTMLInject:") == 0){
    Also some code before swap to strip off this prefix.
    Use alternative hidden columns to render HTML fields for other formats (DOC, EXCEL, etc). HINT: "Show or hide based on an expression" with "=Globals!RenderFormat.Name" and maybe Report's code functions to convert some tags into tags, that's supported by SSRS.
    JS speed tuning on large pages

Leave a Reply

Your email address will not be published. Required fields are marked *