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.

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;

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.

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.

Build your application and open the web page in your browser. You will have an output as below;

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.

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.

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.

About Gopal Krishna Ranjan

Gopal has 8 years of industry experience in Software development. He has a head down experience in Data Science, Database, Data Warehouse, Big Data and cloud technologies and has implemented end to end solutions.
He has extensively worked on SQL Server, Python, Hadoop, Hive, Spark, Azure, Machine Learning, and MSBI (SSAS, SSIS, and SSRS). He also has good experience in windows and web application development using ASP.Net and C#.