Display Label Text With Line Breaks in C#

Display label text with line breaks in c#

You may append HTML <br /> in between your lines. Something like:

MyLabel.Text = "SomeText asdfa asd fas df asdf" + "<br />" + "Some more text";

With StringBuilder you can try:

StringBuilder sb = new StringBuilder();
sb.AppendLine("Some text with line one");
sb.AppendLine("Some mpre text with line two");
MyLabel.Text = sb.ToString().Replace(Environment.NewLine, "<br />");

Add NewLine to label's Text at design time

When you click on the label Text property in the Property window for the label, a drop down will appear in which you can, when you press Enter, go to the new line. I just tried it, and it works in Visual Studio 2010.

Here's a screenshot to clarify:

Editing multiline label

How to break lable text line in asp.net c#

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

How to show new line in label

simply try this

lbl.Text="India\r\nis\r\nbest".Replace(Environment.NewLine, "<br />");

asp net label break line after x characters

You can use CSS word-wrap: break-word; which will fix this.

Example:

#par1 {  word-wrap: break-word;}
<p id="par1">  Very long texttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt</p>

Visual Studio - Add a line break in a label via the designer?

Select the dropdown next to the label. Then you can just use the Enter key to enter line breaks.

asp:label does not respect line breaks read in from text file. Line wrap is not as intended

You're outputting the text directly to HTML with your Label.

Change the newline character to <br /> and you're golden:

lblReleaseNotes.Text = sr.ReadToEnd().Replace("\n", "<br />");


Related Topics



Leave a reply



Submit