Text wrapping in SSRS Reports in ReportViewer Control

In this blog post “Report Viewer wrap text”, we are going to learn an important trick of text wrapping in SSRS reports for long texts (without space and any separator) exceeding the width of a report column’s defined width and being rendered in a Report Viewer control of .Net  Application. Below is the problem explanation in more detail;

I have a report which is rendering through a ReportViewer control in a .Net Web Application. I have defined the width of each and every column in my report. As there are multiple columns in my report and some of which contains long texts without any space or separator. What i want, if the text is too long to fit as per the defined width, the text should be wrapped in next row. I don’t want to expand the column width to accommodate this text in one row. In other words, I want to wrap the text in next row if the text inside this columns exceeded the width of the column defined in the SSRS report. And I am getting this behavior of the report if i am running my report on my Report Server directly. But if the same report is being rendered in a Report Viewer control in my web application, the column is being expanded to accommodate the text in one row. Remember that the long text does not contain any space or separator type characters.

Impact of text wrapping in report project and on report server

Like other articles, lets start this too with some demo and sample codes. Follow these steps to create a sample application and produce this on your machine.

  • Create a report server project in SQL Server Data Tools (SSDT)
  • Add a Datasource and a Dataset in the report.
  • In query type of Dataset, select “Text”.
  • Add below as query in “Query” box of the Dataset. You can also write your own query.
SELECT 'ThisTextDoesNotContainAnySpace' AS Comment
UNION ALL
SELECT 'ThisTextDoesNotContainAnySpace' AS Comment
UNION ALL
SELECT 'ThisTextDoesNotContainAnySpace' AS Comment
  • In above query, we have a text string without any space as a column named “Comment”. Now add a “Table” control from Report Item’s tollbox on the report body and select this column named “Comment” in the table to display. Remember you have fixed the column width less than the above string’s length to produce the mentioned issue.
  • Click on “preview” button to check the output locally. The text should be wrapped to the next row if it exceeds the width of the column. Below is the screen shot.
  • report viewer text wrap
    Fig : Output of the report from Preview button click
  • In above image you can see that this text could not be accommodated in one row in this column and has been wrapped in multiple rows. But the width of the column is constant as desired.Below i will show you the output of this report after deploying it on report server. I have deployed the same report on my local report server and executed from report server. Below is the screen shot;
  • report viewer text wrap
    Fig : Output of the report from report server

Again you can see that we have the desired output i.e. text wrapping is taken care as per the column width.

Impact of text wrapping in ReportViewer Control

Now we have to check the same report in a report viewer control. To do so, follow these steps;

  • Create a Asp.Net Web Application in Visual Studio.
  • Make appropriate changes in web.config file. What i did on my machine is below.
  • <system.webServer>
    <handlers>
    <add name="ReportViewerWebControlHandler" preCondition="integratedMode" verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
    </handlers>
    </system.webServer>
    
  • Add an .aspx web form in the project and on this page register the report viewer control as below. Before that also add the reference of reportviewer assembly in project references.
  • <%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=11.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>
    
  • Add a report viewer control on this page and a script manager too like below.
  • <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
    <div>
    <rsweb:ReportViewer ID="ReportViewer1" runat="server" Width="1000">
    </rsweb:ReportViewer>
    </div>
    </form>
    
  • Write a code to display your report from this report viewer control in .cs file of this web page like below. You can modify the below code as per your need. I did not have any parameter in my report to keep this demo simple and to focus in main issue.
  • if (!IsPostBack)
    {
    ReportViewer1.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote;
    
    Microsoft.Reporting.WebForms.ServerReport serverReport = ReportViewer1.ServerReport;
    
    // Set the report server URL and report path
    serverReport.ReportServerUrl = new Uri("http://mymachine/reportserver");
    serverReport.ReportPath = "/TestReports/TextWrapping";
    }
    
  • Build your application and open the web page in your browser. You will have an output as below;
  • report viewer text wrap
    Fig : Output of the report rendered in report viewer control on web page

In above figure, you can see that the output of the same report has been changed. The text wrapping is not working as it worked in above cases which was desired too. In this case width of the column is expanding to accommodate the text instead of wrapping the text in more than one row.

Enable Text wrapping in SSRS reports rendered in report viewer control on web page

As of now and what i know, there is no any staright forward method to achieve this task and to do this we have to folk it as below;

  • To render this report with text wrapping, follow these steps;
  • To avoid rework, go to your report project and click on the textbox which holds this data inside the table and press ctrl + X to cut it from the table.
  • Drag and drop a rectangle control in the table’s cell from the Report Item’s toolbox.
  • Press ctrl + V to put the textbox inside the rectangle.
  • Set the border of the rectangle as your textbox has.
  • Deploy the report and see the output in your browser.
  • report viewer text wrap
    Fig : Output of the report rendered in report viewer control on web page with text wrapping

Conclusion

In one line, we just have to put our text box inside a Rectangle control to get the text wrapping. It will force the text to wrap in more than one row if the text inside the textbox is exceeding the width of the given column.

Hope you have enjoyed this trick and to support my work just rate this post and share it on your social wall. I will be glad to see you in comment section too. Thanks and keep visiting my web portal and register yourself in newsletter to be updated with new releases.

Rate This
[Total: 2 Average: 3.5]

2 thoughts on “Text wrapping in SSRS Reports in ReportViewer Control”

  1. I’ve read some good stuff here. Certainly worth bookmarking for revisiting.
    I surprise how much effort you set to create any such
    excellent informative web site.

Leave a Comment

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


The reCAPTCHA verification period has expired. Please reload the page.

This site uses Akismet to reduce spam. Learn how your comment data is processed.