Keeping text control characters (line breaks / carriage returns) in DetailsView field

Discussion in 'ASP .Net' started by Bazza Formez, Aug 1, 2007.

  1. Bazza Formez

    Bazza Formez Guest

    I have a bound field in a DetailsView control that displays free form
    description type data from my SQL database table (typical data is a
    couple of paragraphs of written product description being held in a
    single database field of type ntext).

    This description data typically has various simple control characters
    in it - ie. new line, carriage returns etc) to make the paragraph more
    readable.

    My problem is that these control characters are lost / don't work....
    When I run the application all text in the field displays as a simple
    lump of text.. without any new lines etc.

    Below is the simple definition I am using inside the DetailsView..

    <asp:BoundField DataField="Description" HeaderText="Description"
    SortExpression="Description" />

    Can anyone suggest a solution ?

    Thanks,
    Bazza
    Bazza Formez, Aug 1, 2007
    #1
    1. Advertising

  2. On Aug 1, 10:57 pm, Bazza Formez <> wrote:
    > I have a bound field in a DetailsView control that displays free form
    > description type data from my SQL database table (typical data is a
    > couple of paragraphs of written product description being held in a
    > single database field of type ntext).
    >
    > This description data typically has various simple control characters
    > in it - ie. new line, carriage returns etc) to make the paragraph more
    > readable.
    >
    > My problem is that these control characters are lost / don't work....
    > When I run the application all text in the field displays as a simple
    > lump of text.. without any new lines etc.
    >
    > Below is the simple definition I am using inside the DetailsView..
    >
    > <asp:BoundField DataField="Description" HeaderText="Description"
    > SortExpression="Description" />
    >


    instead of BoundField use a TemplateField

    <asp:TemplateField>
    <ItemTemplate>
    <%# Replace(Container.DataItem("Description"), vbCrLf, "<br>") %>
    </ItemTemplate>
    </asp:TemplateField>

    and in C# use

    Replace("\n", "<br>");
    Alexey Smirnov, Aug 1, 2007
    #2
    1. Advertising

  3. Bazza Formez

    Bazza Formez Guest

    On Aug 2, 9:24 am, Alexey Smirnov <> wrote:
    > On Aug 1, 10:57 pm,BazzaFormez<> wrote:
    >
    >
    >
    >
    >
    > > I have a bound field in a DetailsView control that displays free form
    > > description type data from my SQL database table (typical data is a
    > > couple of paragraphs of written product description being held in a
    > > single database field of type ntext).

    >
    > > This description data typically has various simple control characters
    > > in it - ie. new line, carriage returns etc) to make the paragraph more
    > > readable.

    >
    > > My problem is that these control characters are lost / don't work....
    > > When I run the application all text in the field displays as a simple
    > > lump of text.. without any new lines etc.

    >
    > > Below is the simple definition I am using inside the DetailsView..

    >
    > > <asp:BoundField DataField="Description" HeaderText="Description"
    > > SortExpression="Description" />

    >
    > instead of BoundField use a TemplateField
    >
    > <asp:TemplateField>
    > <ItemTemplate>
    > <%# Replace(Container.DataItem("Description"), vbCrLf, "<br>") %>
    > </ItemTemplate>
    > </asp:TemplateField>
    >
    > and in C# use
    >
    > Replace("\n", "<br>");- Hide quoted text -
    >
    > - Show quoted text -


    Thank you very much Alexey!
    Bazza Formez, Aug 6, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dr. Laurence Leff
    Replies:
    4
    Views:
    5,700
    Stanimir Stamenkov
    Dec 29, 2004
  2. Dave
    Replies:
    3
    Views:
    506
    nick chan
    Jul 2, 2008
  3. bernadou

    Force multi line field value to output with line breaks?

    bernadou, Jan 22, 2006, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    332
    bernadou
    Jan 23, 2006
  4. Les Juby
    Replies:
    4
    Views:
    237
    Bullschmidt
    Aug 30, 2005
  5. Marek Stepanek
    Replies:
    12
    Views:
    395
    Peter J. Holzer
    Sep 2, 2006
Loading...

Share This Page