Breaks in labels

C

Chris

I am writing some text in a multiline text box to a database . When I
display this in a label all the breaks have disappeared. I will be using
formviews a lot so I need a solution that works with bound data. In ASP I
used to use the replace function to replace chr(13) with "<br>". I am not
sure the how to do this in .net. Is there some simple setting or do I have
create my own version of a label and overide an event. I am a little unsure
of how to do this. Regards, Chris.
 
M

Mark Rae

Chris said:
I am writing some text in a multiline text box to a database . When I
display this in a label all the breaks have disappeared. I will be using
formviews a lot so I need a solution that works with bound data. In ASP I
used to use the replace function to replace chr(13) with "<br>". I am not
sure the how to do this in .net. Is there some simple setting or do I have
create my own version of a label and overide an event. I am a little unsure
of how to do this. Regards, Chris.


string strText = "This is a multiline label\\r\\nwith a line break";
MyLabel.Text = strText.Replace(\\r\\n, "<br />");
 
C

Chris

Is there any way of building a composite control and overiding its databound
(I'm guessing the event name) so I can use the label without do the code all
the time? Bear in mind I am quite new the .net. Regards, Chris.
 
M

Mark Rae

B

bruce barker

your own control is a good solution and pretty simple:


public class MultiLineLabel : Label
{
override string Text
{
get {return base.Text;}
set {base.Text = value.Replace("\\r\\n","<br />"); }
}
}


-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top