Replacing new line with HTML break from SQL data

dageyra
dageyra used Ask the Experts™
on
I am pulling some data from a table where a column has its data delimitted via new line, \n.  This data is going to be presented to the page, so the \n needs to be converted to <br />.  I am using SQL's replace function to handle this conversion, which works fine.  The data is bound to a DetailsView, which is where things go wrong.  Instead of seeing the data all lined up nicely, the <br /> is turned into &lt;BR/&gt;, basically the HTML encoding equivalent of <br />.  I know that when I get the data from SQL Server, it is not encoded, so I presume the DetailsView is causing the problem.

How can I get around this issue with the DetailsView or is there an alternative method I could try?
I Do Not Smoke&lt;BR/&gt;
My Roommate Should Not Smoke&lt;BR/&gt;
I Have Pets&lt;BR/&gt;
I Have Pets In My Home&lt;BR/&gt;
I Prefer A City Location&lt;BR/&gt;
I Need At Least7 Or8 Hours Of Sleep&lt;BR/&gt;
 
I Prefer Loud Music&lt;BR/&gt;

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Here is a sample i tried with your text
     <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataMember="DefaultView"
            DataSourceID="SqlDataSource1" Height="50px" Width="144px">
            <Fields>
                <asp:BoundField DataField="Text" HeaderText="Text" SortExpression="Text" />
                <asp:TemplateField><ItemTemplate><%#Replace(Container.DataItem("Text"), vbCrLf, "<BR>")%>
                </ItemTemplate>
                </asp:TemplateField>
            </Fields>
        </asp:DetailsView>

Open in new window

Author

Commented:
I modified your suggestion slightly (I did not need the BoundField at all), but worked like a charm.  Thanks for the help.

Author

Commented:
Perfect

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial