Last post Mar 31, 2010 01:42 AM by shwpun
Jan 07, 2009 02:53 PM|voorheis|LINK
I'm trying to display some comments that users enter into a textbox that's bound to an Access database. After the data is entered/edited it's displayed with a label field. Is there an easy way (any way really, since I can't do this now) to show the line
breaks that the users have entered?
Jan 07, 2009 03:13 PM|ecbruck|LINK
Here's one way you might do it:
string s = "First line" + Environment.NewLine + "Second line";
string x = s.Replace(Environment.NewLine, "<br />");
Jan 07, 2009 03:15 PM|kipo|LINK
I assume that you have a Label which looks something like this:
<asp:Label ID="Label1" runat="server" Text='<%# Eval("Comments") %>'></asp:Label>
<asp:Label ID="Label1" runat="server" Text='<%# GetLineBreaks(Eval("Comments")) %>'></asp:Label>
public string GetLineBreaks(object Comments)
return (Comments.ToString().Replace(Environment.NewLine, "<br/>"));
Jan 07, 2009 03:20 PM|Mohid|LINK
You can use string.replace() method on the string value of the text box which will show line breaks on the web page. You don't necessarily have to save these changes to db instead you can just perform this replace right before you bind your text value to
the label (or some other control you use) on the web page.
String .Replace("\n", "<br>");
Depending on which browser you use (IE or Firefox) you can use one of the statement.
Just a FYI: IE and Firefox produce different line breaks.
Hope that helps. :)
Jan 07, 2009 08:49 PM|voorheis|LINK
thanks guys, here's what I ended up using:
Mar 31, 2010 01:42 AM|ShwPun|LINK
I wnt the code in Vb.net..Can u plz assist me...