Search my blog

Some of my readers



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 ]