Wednesday 23 January 2013

Display the Content of Multiline Textbox Line By Line after Retrieval


Display the Content of Multiline Textbox Line By Line after Retrieval


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.

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 and "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.

No comments:

Post a Comment

Thank You for Your Comments. We will get back to you soon.

back to top