473,320 Members | 1,719 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

DB Text with NewLines, etc. for display in a Repeater or DataGrid

If I have text data from a database which will contain NewLine characters
because it was entered from a Multi-Line TextBox, and now I want to display
the output in a Repeater or other DataBound List Control, how can I set it up
so that it'll properly show the text with the paragraph breaks, etc?

At first, I thought I'd just have to write a routine that did
s = s.Replace(Environment.Newline, "<br/>");
and that works fine for showing simple, one-off text. But if I want to put
this in a Repeater, how can I run my "Replace" function in-line in the
ItemTemplate of the repeater? Can I? If so, can you show me the syntax for
how to do that? Is this the bext way to do it?

Thanks.

Alex
Jun 14 '06 #1
2 1504
Hi Alex,

Here it is (assume you're using ASP.NET 2.0):

================
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
<ItemTemplate>
<br /><hr /><br />
CategoryName:<%# Eval("CategoryName") %>
<br />
CategoryName:<%#
Eval("Description").ToString().Replace(Environment .NewLine,"<br/>") %>
</ItemTemplate>
</asp:Repeater>
==================

Hope this helps.

Regards,

Steven Cheng
Microsoft MSDN Online Support Lead
==================================================

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.

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Jun 14 '06 #2
or you could always wrap it in <pre></pre> tags, that way it maintains
all formatting (if there's extra spaces or tab characters or something
like that)
Steven Cheng[MSFT] wrote:
Hi Alex,

Here it is (assume you're using ASP.NET 2.0):

================
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
<ItemTemplate>
<br /><hr /><br />
CategoryName:<%# Eval("CategoryName") %>
<br />
CategoryName:<%#
Eval("Description").ToString().Replace(Environment .NewLine,"<br/>") %>
</ItemTemplate>
</asp:Repeater>
==================

Hope this helps.

Regards,

Steven Cheng
Microsoft MSDN Online Support Lead
==================================================

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.

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)


Jun 15 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Stephen Miller | last post by:
I am using the OnItemDataBound event of Repeater control to nest a DataGrid within the Repeater. When I attempt to bind to the DataGrid using the DataSource method I get the error message "Object...
1
by: Marco Antonio Montalvo Durán | last post by:
hello everybody!!!, I made a list of links to different URL's using a Repeater. what I'm trying to do is to get the position in the repeater where clicked. Does somebody know how can I do it??...
2
by: A Traveler | last post by:
Hi, I have a custom collection class i wrote, LineItemsCollection, which is a strongly typed collection of objects of my LineItem class. The LineItem class is a simple class with just a couple...
0
by: Ferret | last post by:
I've found what seems to be a nasty bug in the DataGrid and Repeater classes. If CreateChildControls gets called before LoadViewState, ViewState fails to map and you end up with nothing on a...
3
by: Kevin Cunningham | last post by:
I have a repeater with some labels in it (code below). For whatever reason the text for the label is not persisted in viewstate on the postback. Is there a trick to get this to work? Is there...
4
by: Brent | last post by:
My SQL might generate a result like this: Security 2005-06-30 2005-03-31 2004-12-31 IBM $65 $100 $123 (etc) or like this: Security 2005-06-30 2005-03-31
1
by: Kas_aspnet | last post by:
Hi, I have to display a sequence of records in an Aspx page. The problem is, i have to display the records by checking conditions like Classic ASP. For example, consider an employee table. In...
1
by: Kim | last post by:
How can I display "No data found" in the repeater if there are no records found after selecting an item from a dropdown list. Another question is: Can repeater perform paging as in datagrid if...
1
by: sck10 | last post by:
Hello, I am inserting the values for radio buttons on a form into a database. There are 25 questions with 4 possible answers (see below). Is it possible to pragmatically build the radio button...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.