Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I preserve line breaks in my displayed data? 1

Status
Not open for further replies.

autumnEND

Programmer
Nov 1, 2005
61
0
0
GB
Im new to asp net, and am having trouble preserving line breaks in the displayed data
The data is entered using a MultiLine text box, and stored in a sql database. And then the displayed data is displayed in a label , The label is situated insde a DataList control. As can be seen below

<asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1">
<ItemTemplate>
<Asp:Label ID="newsARTICLELabel" runat="server" Text='<%# Eval("newsARTICLE") %>'>
</Asp:Label>
</ItemTemplate>
</asp:DataList>

Does anyone know how i can , display (preserve) the line breaks?

I have done this in asp using mx2004, but cant seem to get this to work using Microsoft visual web.

Any pointers would be appreciated. thanks.
 
Text='<%# Replace(Server.HTMLEncode(Eval("newsARTICLE")),vbcrlf,"<br>") %>

May have to make some small adjustments for C#
 
Hi thanks for the reply, i entered the code as below.

<Asp:Label ID="newsARTICLELabel" runat="server" Text='<%# Replace(Server.HTMLEncode(Eval("newsARTICLE")),vbcrlf,"<br>") %>'> </Asp:Label>

when i ran the page it gave an error of " Compiler Error Message: BC30512: Option Strict On disallows implicit conversions from 'System.Object' to 'String'"

i have the data stored in the database as varchar(max)maybe this is causing a problem, or maybe the fact that its displayed in a label is a problem


 
Text='<%# Replace(Server.HTMLEncode(Convert.ToString(Eval("newsARTICLE"))),vbcrlf,"<br>") %>

You need to convert to string then.
 
An alternative would be putting the data in a table instead of a label, setting the width to whatever width you want (the same width as your multiline textbox?) and allow text wrap within the row.
 
Or you could simply replace the data in the actual sql then you don't need to apply any formatting at all.



____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top