Using line breaks in text

D

David

We have VS2005 ASP.NET 2.0 application that needs to have each paragraph
separated by a line break. I have added "<br />" into the text column (SQL
2000) and it works fine when displaying on a web page (GridView). However,
when I export the to Excel it creates separate rows for each line break, but
I don't want that. Does anyone have a solution? Thanks.

David
 
M

Mark Fitzpatrick

You could simply do a replace on the text field to replace the linebreak
with either nothing, or a carriage return. I forget which delimiter Excel
will interpret as the need for a new row so you may have to experiment. You
could do something like .Replace("<br />","") to replace it with nothing
(this is of course used when pulling the data from the database. If you
can't do it at this stage, ie: if you're binding directly to a datareader,
you could have SQL Server do the replacement for you before it gets passed
out to the reader. If I remember correclty, SQL Server does have string
replacement functions.
 
K

Kevin Spencer

Leave the original Line breaks in the database. These are not really part of
the text (data), but part of the UI-specific formatting. Your ASP.Net app
should replace these with "<br />" during execution.

--
HTH,

Kevin Spencer
Microsoft MVP
Chicken Salad Shooter
http://unclechutney.blogspot.com

A man, a plan, a canal, a palindrome that has.. oh, never mind.
 
D

David

You are a genius! I just put code into RowDataBound and did the replacement
when sending to Excel. It seems to work fine and with the "<br />" still in
there, the web pages show what I want. The only downside is that the Excel
field does not have line breaks. Below is my VB code doing the replace.
Does it look ok to you?

strnote = strnote.Replace("<br />", vbCrLf)

David
 
K

Kevin Spencer

Looks fine to me, David. Except that I would simply store the native data
(no HTML markup) in the database. This way, the data is not linked in any
way to any user interface, and it is the responsibility of the interface to
do any transforming.

--
HTH,

Kevin Spencer
Microsoft MVP
Chicken Salad Shooter
http://unclechutney.blogspot.com

A man, a plan, a canal, a palindrome that has.. oh, never mind.
 
D

David

Kevin,
Good point. What exactly would you store in the database to represent CrLf?
Thanks.
David
 
R

Russell

As he said earlier

Leave the original Line breaks (CrLf) in the database...

Your ASP.Net app should replace these with "<br />" during execution.

(You must code for this.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top