[英]How to break lable text line in asp.net c#
I'm new to asp.net and recently I made a guestbook and I don't know how to break body lable text. 我是asp.net的新手,最近我做了一个留言簿,但我不知道该如何破坏正文标签文本。 I used this code which cannot solve my problem:
我使用以下代码无法解决我的问题:
<asp:ListView ID="ListView1" runat="server" DataKeyNames="UserID"
DataSourceID="SqlDataSource1">
<AlternatingItemTemplate>
<tr style="background-color: #FFFFFF;color: #284775;">
<td>
<asp:Label ID="SubjectLabel" runat="server" Text='<%# Eval("Subject") %>' />
</td>
<td>
<asp:Label ID="CommentDateLabel" runat="server"
Text='<%# Eval("CommentDate") %>' />
</td>
<td>
<asp:Label ID="BodyLabel" runat="server" Width="300" Text='<%# Eval("Body").ToString().Replace("\r\n", "<br />") %>' />
</td>
<td>
<asp:Label ID="UserNameLabel" runat="server" Text='<%# Eval("UserName") %>' />
</td>
<td>
<asp:Label ID="UserurlLabel" runat="server" Text='<%# Eval("Userurl") %>' />
</td>
<td>
<asp:Label ID="UserIDLabel" runat="server" Text='<%# Eval("UserID") %>' />
</td>
<td>
<asp:Label ID="CommentIdLabel" runat="server" Text='<%# Eval("CommentId") %>' />
</td>
</tr>
</AlternatingItemTemplate>
Text='<%# Eval("Body").ToString().Replace(Environment.NewLine, "<br />" ) %>' />`
I searched every where in google and bing etc without success, can anyone help me about solve this problem? 我在google和bing等中搜索的所有位置均未成功,有人可以帮助我解决此问题吗?
Try it 试试吧
<asp:Label ID="BodyLabel" **style="word-wrap: break-word"** runat="server" Text='<%# Eval("Body").ToString() %> />
or look at this sample : Adding new line to label 或查看此示例: 在标签上添加新行
The answer is you just add <br/>
string into you Label text. 答案是您只需在标签文本中添加
<br/>
字符串。 Because the Label is a span tab in html, like this: 因为标签是html中的span标签,所以像这样:
<asp:Label ID="SubjectLabel" runat="server" Text='<%# Eval("Subject") %><br/>' />
You can use Replace("\\r\\n", "<br />");
您可以使用
Replace("\\r\\n", "<br />");
in your tag 在您的标签中
Text='<%# Eval("Body").ToString().Replace("\r\n", "<br />") %>' />
combining 结合
<asp:Label ID="BodyLabel" runat="server"
Text='<%# Eval("Body").ToString().Replace("\r\n", "<br />") %>' />
Just specify the Width
: 只需指定
Width
:
<asp:Label ID="BodyLabel" Width="300px" runat="server" Text='<%# Eval("Body").ToString() %> />
Or - If you want exact breaks just do: Replace("\\n", "<br />");
或者-如果您想精确休息,请执行以下操作:
Replace("\\n", "<br />");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.