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.
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.
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.
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.
//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)
}
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 >