|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Convert New Lines to BRsconnects to a microsoft sql database, runs a sql query and then prints that data out using a repeater. The problem is that the data in the database is in plain text and contains new lines (\n). When I print the records I need convert new lines to <br>'s. Is there an easy way to do this? Here is where I am printing the data. <ASP:Repeater id="results_repeater" runat="server"> <HeaderTemplate> <table> </HeaderTemplate> <ItemTemplate> <tr> <td><%# DataBinder.Eval(Container.DataItem, "IEDescription") %> </td> </tr> </ItemTemplate> <FooterTemplate> </table> </FooterTemplate> </ASP:Repeater> Thanks, Brad Hi Brad,
Welcome to the ASPNET newsgroup. As for the displaying newline in web page for the text data from database, I think you can consider using the string.replace method. And the linefeed in normal text can be represented by the following characters: "\r\n" (in c#) So we can just use this function in our databinding expression.e.g: <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "IEDescription").ToString().Replace("\r\n","<br/>") %>'></asp:Label> </ItemTemplate>Also, you can also define a custom helper function in page's code behind class and call it in databinding expression to do the work, like: <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%# CustomFunc(DataBinder.Eval(Container.DataItem, "IEDescription")) %>'></asp:Label> </ItemTemplate> Hope this helps. Regards, Steven Cheng Microsoft Online Community Support ================================================== When responding to posts, please "Reply to Group" via your newsreader so that others may learn and benefit from your issue. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. Create a method in your CodeBehind that takes a string as an argument, and
replaces all line breaks with "<br>" tags, such as the following: protected string ConvertBr(string s) { return s.Replace("\n", "<br>\n"); // Kept the newline for HTML Then, in your Repeater, call that function, like so:formatting } <%# ConvertBr(Container.DataItem["IEDescription"]) %> -- Show quoteHide quoteHTH, Kevin Spencer Microsoft MVP Professional Numbskull Show me your certification without works, and I'll show my certification *by* my works. "Brad Baker" <brad@nospam.nospam> wrote in message news:uMaOow3XGHA.4432@TK2MSFTNGP04.phx.gbl... > I'm trying to write a small asp.net webpage in c#. I've written code which > connects to a microsoft sql database, runs a sql query and then prints > that data out using a repeater. > > The problem is that the data in the database is in plain text and contains > new lines (\n). When I print the records I need convert new lines to > <br>'s. Is there an easy way to do this? > > Here is where I am printing the data. > > <ASP:Repeater id="results_repeater" runat="server"> > <HeaderTemplate> > <table> > </HeaderTemplate> > <ItemTemplate> > <tr> > <td><%# DataBinder.Eval(Container.DataItem, "IEDescription") %> </td> > </tr> > </ItemTemplate> > <FooterTemplate> > </table> > </FooterTemplate> > </ASP:Repeater> > > Thanks, > Brad >
Other interesting topics
New to ASP
Help removing a reference in a web site how do yoiu ASP.NET from changing the id attribute???? ASP.NET: Can't Kill EXCEL.exe with Office PIA Update Query in formview Anyone care to help explain forms authentication in 2.0? Translating ID bound to label in detailsView to NAME basing on different datasource. Determine Debug Mode Parsing Request.Headers.ToString() DataGrid Delete Problem |
|||||||||||||||||||||||