Reputation: 759
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.
Upvotes: 2
Views: 28423
Reputation: 499052
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.
Upvotes: 4
Reputation: 1
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.
Upvotes: 0
Reputation: 1509
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 >
Upvotes: 1
Reputation: 16011
//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)
}
Upvotes: 0
Reputation: 60065
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.
Upvotes: 1