开发者

Adding new line to label

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. B开发者_运维问答ecause after 35 charecters the text overflows.

Can you please let me know how to do this.


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.


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.


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 >


//assuming l is a label
for (int i = 0; i < l.Text.Length; i++)
{
  if (i % 35 == 0)
    l.Text.Insert(i, Environment.NewLine) // or use "<br />" for html break since browsers ignore whitespace (except IE 6 in some cases)
}


On Properties window you can change the label's Width and Height. You should set the label size based on the size of window and size of label type must pixel.


use Environment.NewLine
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜