tags:

views:

173

answers:

3

Hello, I've got a weird issue,

i've got a datarepeater that reads some user entries froma database, and then shows them in an <asp:label> ..

my 1st problem was that when the text is read all \ns got dropped ..

so I use a <pre> tag to solve the problem.. however... a new problem occurred.. now the text actually goes beyond the label's border..

<td width="630px" >
 <pre>
   <asp:Label ID="lblComments"  runat="Server" 
       width="630px" Text='<%#DataBinder.Eval(Container.DataItem, "Comments") %>'
       Style="font-size: larger">
   </asp:Label>
  </pre>
</td>
+4  A: 

<pre> means preformatted so no additional line breaks are added to the text.

You'll have to shorten the line lengths in the preformatted text.

pavium
Sry had to switch the answer to zhaph.. cause it solved it without forcing me to modify the design :)
Madi D.
Oh well, you win some, you lose some.
pavium
+5  A: 

Yep, a pre will just output the text with little or no regard to the layout of the page.

You should be formatting the text from the database to convert \n's into <br/>s.

You should be able to get away with something like:

<%# DataBinder.Eval(Container.DataItem, "Comments")
                   .ToString().Replace("\n", "<br />") %>
Zhaph - Ben Duguid
This would be my recommendation, but just to note it isn't full-proof - if data came from user input it could be \r\n or \r as well, not sure Environment.NewLine would help in this instance (unless you normalize new lines on all user input)
roryf
True enough, and I did nearly use Environment.NewLine. However, they will either be \n or \n\r, but I've never seen just \r, so you could get away with replacing just the \n and ignoring the \r, which wouldn't have any affect on the displayed output.
Zhaph - Ben Duguid
oh.. ur missing a .tostring() :D ..or (string) case.. but thx works like a charm.. !!
Madi D.
Cheers, updated.
Zhaph - Ben Duguid
A: 

Use the css property "pre {white-space: normal;}" Does that work?

Erik5388