Is it possible to display the label text with line breaks exactly as per the image
You can also use <br/>
where you want to break the text.
Following line worked for me:
lbTabRes.Text += num + " x " + i + " = " + (num * i).ToString() + "<br/> \n";
I had to replace new lines with br
string newString = oldString.Replace("\n", "<br />");
or if you use xml
<asp:Label ID="Label1" runat="server" Text='<%# ShowLineBreaks(Eval("Comments")) %>'></asp:Label>
Then in code behind
public string ShowLineBreaks(object text)
{
return (text.ToString().Replace("\n", "<br/>"));
}
Or simply add one line of:
Text='<%# Eval("Comments").ToString().Replace("\n","<br />") %>'
Also you can use the following
@"Italian naval...<br><br>"+
Above code you can achieve double space. If you want single one means you simply use
.
I know this thread is old, but...
If you're using html encoding (like AntiXSS), the previous answers will not work. The break tags will be rendered as text, rather than applying a carriage return. You can wrap your asp label in a pre tag, and it will display with whatever line breaks are set from the code behind.
Example:
<pre style="width:600px;white-space:pre-wrap;"><asp:Label ID="lblMessage" Runat="server" visible ="true"/></pre>