Adding new line to label

27,732

Solution 1

Just change the style of the label so it will wrap the text:

style=" width:50px; overflow-y:auto;overflow-x:auto; word-break:break-all;"

Better yet, put this in your CSS file rather than directly on the control.

Another option, if you don't like this, is to use a textbox and style it as a label, as described in this post.

Solution 2

quick psuedo code

string s = 'value from db';
string s2 = "";
int len = s.Length;
int i = 0;
while ( i + 35 > len ) {
  s2 += s.Substring( i, 35 ) + "\r\n";
  i+=35;
}
s2 += s.Substring( i, len - i );
label.Text = s2;

if \r\n does not work, replace it with < br >

Solution 3

there is no way to do this, you would better create more labels. you could add <br/>, but asp.net will screen it. consider putting single label inside div with fixed width, the text should go to new line automatically.

Share:
27,732
xrx215
Author by

xrx215

Updated on August 20, 2020

Comments

  • xrx215
    xrx215 over 3 years

    I get the data from the database and display that data on the label. I have to apply new line on the text of the label for every 35 charecters. Because after 35 charecters the text overflows.

    Can you please let me know how to do this.