开发者

When using <pre> tag, text goes outside parent <asp:label> border

开发者 https://www.devze.com 2022-12-08 00:41 出处:网络
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> ..

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>


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 />") %>


<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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消