469,950 Members | 2,353 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,950 developers. It's quick & easy.

Carriage Returns

In ASP using VBScript to replace Chr(13) or Chr(10) with a <br> tag I would
use the Replace method so that I can catch carriage returns from a memo field
in MS Access or a Text field in MS SQL Server. For instance
<%=Replace(rs.Fields.Item("column").Value),Chr(13) ,"<br />")%>. I am, now,
migrating to ASP.NET 1.1 and am using C# as the primary programming language.
In one of my contracts I have a database table with a field that must be a
text field in SQL Server that must hold carriage returns which does not
convert to <br> when I serve up the data field. The table in the database
that holds the text field is a child table of another table. I need to be
able to convert a new line "\n" to the HTML equivalent "<br />"
programatically. Nothing I have done has worked. So far I have tried:

<asp:Repeater ID="SomeDataSource" Runat="Server">
<ItemTemplate>
<%# Databinder.Eval(Container.DataItem, "SomeField").Replace("\n",
"<br>")%>
</ItemTemplate>
</asp:Repeater>
But that does not work. I keep on getting an error that says 'Replace'
associated with the object 'Whateverpage.aspx'
or I get an error that states something to the effect that a method was
expected but got a property-- something like that error-- the meaning is the
same. Whatever the case I think I'm getting something wrong.

If anyone can tell me where I am going wrong I would greatly appreciate it.

Thank you,

Sam-
Nov 18 '05 #1
1 2456
Hello I am Sam" I am,

You probably need to cast from the object to a string...

try something like this (untested): <%# ((string)DataBinder.Eval(Container.DataItem, "SomeField")).Replace("\n", "<br>"); %>

--
Matt Berther
http://www.mattberther.com
In ASP using VBScript to replace Chr(13) or Chr(10) with a <br> tag I
would
use the Replace method so that I can catch carriage returns from a
memo field
in MS Access or a Text field in MS SQL Server. For instance
<%=Replace(rs.Fields.Item("column").Value),Chr(13) ,"<br />")%>. I am,
now,
migrating to ASP.NET 1.1 and am using C# as the primary programming
language.
In one of my contracts I have a database table with a field that must
be a
text field in SQL Server that must hold carriage returns which does
not
convert to <br> when I serve up the data field. The table in the
database that holds the text field is a child table of another table.
I need to be able to convert a new line "\n" to the HTML equivalent
"<br />" programatically. Nothing I have done has worked. So far I
have tried:

<asp:Repeater ID="SomeDataSource" Runat="Server">
<ItemTemplate>
<%# Databinder.Eval(Container.DataItem,
"SomeField").Replace("\n",
"<br>")%>
</ItemTemplate>
</asp:Repeater>
But that does not work. I keep on getting an error that says
'Replace'
associated with the object 'Whateverpage.aspx'
or I get an error that states something to the effect that a method
was
expected but got a property-- something like that error-- the meaning
is the
same. Whatever the case I think I'm getting something wrong.
If anyone can tell me where I am going wrong I would greatly
appreciate it.

Thank you,

Sam-


Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Andrew Chanter | last post: by
12 posts views Thread by Nimmy | last post: by
2 posts views Thread by Matt Mercer | last post: by
8 posts views Thread by TheDude5B | last post: by
7 posts views Thread by mattrapoport | last post: by
reply views Thread by markus.shure | last post: by
11 posts views Thread by evenlater | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.