Carriage Returns

Discussion in 'ASP .Net' started by Guest, Oct 15, 2004.

  1. Guest

    Guest Guest

    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-
     
    Guest, Oct 15, 2004
    #1
    1. Advertisements

  2. Guest

    Matt Berther Guest

    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, Oct 16, 2004
    #2
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.