We take pride in your success. We let our positivity drive us, day in and out. Talk to us at Mindfire to know us more.

Software Technology Tips

Problem:
While saving multiline text box values to database and then retrieving it, the line feed character is not displayed on retrieval. For instance, we use a multiline text box to enter address and as often the address consists of multiple lines which are created using the Enter key (carraige return character). Now if we save a multiline address to the database and later retrieve it and display the value on a label, we would find the address shown as a single line and not multiple lines.
Solution:
However, the carriage return information is saved in the database but it is saved as a square symbol. The square symbol actually represents "\r\n" character -  \r  represents carriage return; \n represents new line. 
 
So while displaying the data to the label we simply replace the '\r\n' character with '<br />' .
txtAddress.Text = dtCompanyInfo.Rows[0]["ADDRESS"].ToString().Replace("\r\n", "<br />");

Where "dtCompanyInfo" is the instance of the DataTable
           "txtAddress" is the instance of a TextBox
 
This way we can format the retrieved data so that it can be displayed in the same manner as it was entered, especially when the data contains line feed / carriage return characters.


Related Tags:

Database, Line Feed, Carraige Return, Multiline text box, \r\n

Author: Sachin Kumar

top

ASP.NET

Let us Connect!

privacy

copyright (c) Mindfire Solutions 2007-2012. Login