Chris Crowe's Blog
Ramblings of an IIS MVP ( MVP Since 1997 )

Powered By IIS 7

Search my blog

Some of my readers



My Microsoft Certifications


Dec 15, 1998

Dec 20, 2000

Jan 31, 2001

Jul 22, 2002

Nov 1, 2004

My Microsoft MVP Awards




1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
mvp.support.microsoft.com

When you are delaing with a Repeater or GridView and you have a string which contains embedded Carriage Returns and Line Feeds (CRLF) and you want to display that data using the CRLF you must change them to <BR> tags.

This can be acheived by the simple line below.

Eval("FieldName").ToString().Replace("\r\n", "<BR>")

Normally when you embed data from a database you may use the following Bind But Eval allows you to evaluate a complete expression.

A small sample is shown below <asp:Repeater ID="repComments" runat="server">

<
HeaderTemplate><table cellspacing='0' cellpadding='0' width='650px'></HeaderTemplate>

<
ItemTemplate>
<tr>
  <td>
      <asp:Label ID="lblName" CssClass="commentName" runat="server" Text='<%# Bind("CreatedBy") %>'></asp:Label>
  </
td>
  <td align="right">
     <asp:Label ID="Label1" CssClass="commentDate" runat="server" Text='<%# Bind("CreatedDateTimeUTC") %>'></asp:Label>
  </
td>
</tr>
<tr>
   <td colspan="2"><br />
      <%# Eval("Comment").ToString().Replace("\r\n", "<BR>") %>
      <div style="padding-top: 10px; margin-bottom: 10px; border-bottom: dashed thin;"></div>
   </td>
</tr>
</ItemTemplate>

<FooterTemplate></table></FooterTemplate>

</asp:Repeater>

 

posted on Friday, April 20, 2007 9:05 AM | Filed Under [ ASP.Net ]

Comments


# re: Replacing CRLF with BR in a Repeater or GridView


www.trabajobasura.com/solusoft
Posted by trabajo basura on 8/14/2007 11:15 PM

# re: Replacing CRLF with BR in a Repeater or GridView

Gravatar
I feel your blog is getting spammed...
Posted by Darryl on 3/11/2008 11:43 PM

# re: Replacing CRLF with BR in a Repeater or GridView

Gravatar
Oh and just to correct:

<%#Eval("newsBody").ToString().Replace(vbCrLf, "<br />")%>
Posted by Darryl on 3/11/2008 11:49 PM

# re: Replacing CRLF with BR in a Repeater or GridView

Gravatar
Hie..

it was very helpful.thanks.

My question is how if we want to change two items in a single line

e.g.: <p></p>
Posted by Saritha on 1/14/2009 9:15 PM

# re: Replacing CRLF with BR in a Repeater or GridView

Gravatar
what is CRLF. please put any links to learn more about it.
Posted by Vinoth Kannan S on 3/9/2009 3:34 PM

Post Comment


Title *
Name *
Email
Url
Comment *  
Please add 7 and 8 and type the answer here: