user219628
user219628

Reputation: 3905

Why doesn't the detailsview control display the new line characters on the web page?

In SQL server 2008 R2, I have a table with column containing nvarchar(max) data. When I print the value from this column for one record it displays like this. enter image description here

Using VS2010, I have developed ASP.net web form with DetailsView, which shows above record as shown below. The line carriage and new line characters are lost while displaying on DetailsView !! Question is how can I view new lines?

enter image description here

Upvotes: 0

Views: 794

Answers (2)

user219628
user219628

Reputation: 3905

Solved by using pre (preserve)

pre style="text-overflow: visible;white-space: pre-wrapenter image description here

Upvotes: 1

user756519
user756519

Reputation:

You need to replace newline character \n in the data field with HTML line break <br /> to display the text correctly on a web page.

  • You can replace the characters in the database query or stored procedure before returning the data to the presentation layer.

  • You can replace the characters while binding the data to the control in the presentation layer.

  • You might also want to use a fixed-width font if you want the data to align correctly.

Following link might help you with that.

How to do Replace("\n", "<br />") in detailsview BoundField data control

Upvotes: 1

Related Questions