Force multi line field value to output with line breaks?

Discussion in 'ASP .Net Web Controls' started by bernadou, Jan 22, 2006.

  1. bernadou

    bernadou Guest

    I have a field value that might look like this in the db
    First Line
    Second Line
    Third Line

    When I query the data and output that data to a label in my gridveiw it
    looks like this:
    First Line Second Line Third Line

    How to I insert HTML formatting into the label text so it will render in the
    same fashion it was entered in the db?

    Or in other words, render with "<BR>" tags in place of the line breaks in
    the data?

    Thanks!
    B
     
    bernadou, Jan 22, 2006
    #1
    1. Advertising

  2. Hello again Bernie,

    You can use Environment.NewLine with the Replace method like this:

    <asp:label runat="Server" ID="lblNotes" Text='<%#
    Eval("fldNodes").ToString().Replace(Environment.NewLine, "<br>")
    %>'></asp:label>
    --
    HTH,
    Phillip Williams
    http://www.societopia.net
    http://www.webswapp.com


    "bernadou" wrote:

    > I have a field value that might look like this in the db
    > First Line
    > Second Line
    > Third Line
    >
    > When I query the data and output that data to a label in my gridveiw it
    > looks like this:
    > First Line Second Line Third Line
    >
    > How to I insert HTML formatting into the label text so it will render in the
    > same fashion it was entered in the db?
    >
    > Or in other words, render with "<BR>" tags in place of the line breaks in
    > the data?
    >
    > Thanks!
    > B
     
    Phillip Williams, Jan 22, 2006
    #2
    1. Advertising

  3. bernadou

    bernadou Guest

    Phillip,
    Once again you nailed it. I"ll give this a shot. Much appreciated.

    "Phillip Williams" wrote:

    > Hello again Bernie,
    >
    > You can use Environment.NewLine with the Replace method like this:
    >
    > <asp:label runat="Server" ID="lblNotes" Text='<%#
    > Eval("fldNodes").ToString().Replace(Environment.NewLine, "<br>")
    > %>'></asp:label>
    > --
    > HTH,
    > Phillip Williams
    > http://www.societopia.net
    > http://www.webswapp.com
    >
    >
    > "bernadou" wrote:
    >
    > > I have a field value that might look like this in the db
    > > First Line
    > > Second Line
    > > Third Line
    > >
    > > When I query the data and output that data to a label in my gridveiw it
    > > looks like this:
    > > First Line Second Line Third Line
    > >
    > > How to I insert HTML formatting into the label text so it will render in the
    > > same fashion it was entered in the db?
    > >
    > > Or in other words, render with "<BR>" tags in place of the line breaks in
    > > the data?
    > >
    > > Thanks!
    > > B
     
    bernadou, Jan 23, 2006
    #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. Bazza Formez
    Replies:
    2
    Views:
    934
    Bazza Formez
    Aug 6, 2007
  2. RH
    Replies:
    2
    Views:
    170
  3. Marek Stepanek
    Replies:
    12
    Views:
    420
    Peter J. Holzer
    Sep 2, 2006
  4. VUNETdotUS
    Replies:
    25
    Views:
    461
    Thomas 'PointedEars' Lahn
    Nov 10, 2007
  5. jr
    Replies:
    3
    Views:
    426
Loading...

Share This Page