Wrox Programmer Forums
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 9th, 2008, 03:40 AM
Friend of Wrox
 
Join Date: Jun 2007
Posts: 477
Thanks: 10
Thanked 19 Times in 18 Posts
Default Display Formatting

I have a client that is using an application which connects to an Access database. The application accepts input to a Memo field in the database which is preserving LF and CR characters. However, when the field is pulled into a gridview for display, the text is displaying as one blob; the LF and CR characters are ignored somehow.

Is there a property or method I should call when accessing the database so that this text field includes the formatting?

-------------------------

Whatever you can do or dream you can, begin it. Boldness has genius, power and magic in it. Begin it now.
-Johann von Goethe

When Two Hearts Race... Both Win.
-Dove Chocolate Wrapper

Chroniclemaster1, Founder of www.EarthChronicle.com
A Growing History of our Planet, by our Planet, for our Planet.
__________________
-------------------------

Whatever you can do or dream you can, begin it. Boldness has genius, power and magic in it. Begin it now.
-Johann von Goethe

When Two Hearts Race... Both Win.
-Dove Chocolate Wrapper

Chroniclemaster1, Founder of www.EarthChronicle.com
A Growing History of our Planet, by our Planet, for our Planet.
 
Old March 9th, 2008, 08:49 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Either of these methods should work:

<databaseValue>.Replace(System.Environment.NewLine , "<br />");
<databaseValue>.Replace("\\r\\n", "<br />");

hth

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
 
Old March 10th, 2008, 02:03 AM
Friend of Wrox
 
Join Date: Jun 2007
Posts: 477
Thanks: 10
Thanked 19 Times in 18 Posts
Default

Thank you! OK, so the database may realize what's going on, but it's literally passing the newline as characters and I have to manually convert that into an HTML element if I want the webpage to display properly.

Another question. The context makes sense in the string examples that I've been able to Google on the replace method, e.g. myString = myString.Replace(System.Environment.NewLine, "<br />");

But I'm a little less clear how this will work in my situation. I'm adding the field to the gridview as a bound field on the .aspx page.

e.g. <asp:BoundField DataField="DataEntry" HeaderText="Data" />

I'm assuming that I'll be using DataEntry.Replace(System.Environment.NewLine, "<br />"); somewhere in my code behind?

-------------------------

Whatever you can do or dream you can, begin it. Boldness has genius, power and magic in it. Begin it now.
-Johann von Goethe

When Two Hearts Race... Both Win.
-Dove Chocolate Wrapper

Chroniclemaster1, Founder of www.EarthChronicle.com
A Growing History of our Planet, by our Planet, for our Planet.
 
Old March 10th, 2008, 07:35 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Since you are using a bound field, AFAIK, yes you will need to do this in your code behind before you bind the datasource to the control. If you were using DataBinder.Eval for example, you could add the Replace method directly inside of your gridview.

hth.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor / Author :.
Wrox Books 24 x 7
================================================== =========
 
Old March 17th, 2008, 05:31 AM
Friend of Wrox
 
Join Date: Jun 2007
Posts: 477
Thanks: 10
Thanked 19 Times in 18 Posts
Default

I've decided to beat my head against this one again. I'm using...

protected void sdsDataEntry_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
{
DataEntry.Replace(System.Environment.NewLine, "<br />");
}

I've tried several different variations, but I keep getting errors when I try to compile that say "Data Entry" does not exist in the current context.

PS Don't I need to use the Selected, instead of the Selecting event? I wasn't certain and there's no "SqlDataSourceSelectedEventArgs" so I'm wondering if I'm not approaching that -- among other things ;) -- correctly.

-------------------------

Whatever you can do or dream you can, begin it. Boldness has genius, power and magic in it. Begin it now.
-Johann von Goethe

When Two Hearts Race... Both Win.
-Dove Chocolate Wrapper

Chroniclemaster1, Founder of www.EarthChronicle.com
A Growing History of our Planet, by our Planet, for our Planet.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Tabs Formatting balesh ASP.NET 1.0 and 1.1 Professional 0 June 5th, 2006 11:18 PM
Textbox Formatting echovue Access 5 May 26th, 2006 09:47 AM
Formatting syrex XSLT 2 November 5th, 2005 08:23 AM
Formatting Output Colonel Angus SQL Server 2000 3 September 1st, 2004 10:35 AM
Formatting Ben Access 3 February 28th, 2004 05:52 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.