Keeping text control characters (line breaks / carriage returns) in DetailsView field

B

Bazza Formez

I have a bound field in a DetailsView control that displays free form
description type data from my SQL database table (typical data is a
couple of paragraphs of written product description being held in a
single database field of type ntext).

This description data typically has various simple control characters
in it - ie. new line, carriage returns etc) to make the paragraph more
readable.

My problem is that these control characters are lost / don't work....
When I run the application all text in the field displays as a simple
lump of text.. without any new lines etc.

Below is the simple definition I am using inside the DetailsView..

<asp:BoundField DataField="Description" HeaderText="Description"
SortExpression="Description" />

Can anyone suggest a solution ?

Thanks,
Bazza
 
G

Guest

I have a bound field in a DetailsView control that displays free form
description type data from my SQL database table (typical data is a
couple of paragraphs of written product description being held in a
single database field of type ntext).

This description data typically has various simple control characters
in it - ie. new line, carriage returns etc) to make the paragraph more
readable.

My problem is that these control characters are lost / don't work....
When I run the application all text in the field displays as a simple
lump of text.. without any new lines etc.

Below is the simple definition I am using inside the DetailsView..

<asp:BoundField DataField="Description" HeaderText="Description"
SortExpression="Description" />

instead of BoundField use a TemplateField

<asp:TemplateField>
<ItemTemplate>
<%# Replace(Container.DataItem("Description"), vbCrLf, "<br>") %>
</ItemTemplate>
</asp:TemplateField>

and in C# use

Replace("\n", "<br>");
 
B

Bazza Formez

instead of BoundField use a TemplateField

<asp:TemplateField>
<ItemTemplate>
<%# Replace(Container.DataItem("Description"), vbCrLf, "<br>") %>
</ItemTemplate>
</asp:TemplateField>

and in C# use

Replace("\n", "<br>");- Hide quoted text -

- Show quoted text -

Thank you very much Alexey!
 

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,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top