I am retrieving data from an Oracle database and binding the same to a gridview control.
I noticed that there are instances when the column contains a single quote or double quote, the spaces or whitespace characters get stripped off.
Sample of some data in fields in Oracle:
To Be Phased Out ASAP ‘ “,
When retrieved, it becomes…
To Be Phased Out ASAP ‘ “,
And another one…
IT”S TEST RECORD” DDD ” FFF
which becomes
IT”S TEST RECORD” DDD ” FFF
I don’t have any clue why this is happening…
any ideas?
I think even here the spaces are getting trimmed. In my example in the first field which is:
To Be Phased Out ASAP ‘ “
there are actually two spaces after the single quote but it is displaying just a single space here.. Odd…
single quote space space double quote –> ‘ “
I think the extra space after a quote or single quote is being removed by asp.net??
I also found out that when I am editing my gridview, the extra white spaces are retained but when I go back to the original view, the whitespaces are gone.
To rephrase this question..
How Do I Preserve the WhiteSpace in the gridview when displaying the data?
This is not an ASP.Net thing, it is an HTML parsing thing. If you were to create a plain Jane HTML page with a div tag in it, and then put 100 spaces between the opening and closing tag it would all be condensed into a single space.
This is a classic web issue. If you really want to have everything come out correctly, then you will need to HTML encode any spaces before displaying them on the page.
Try replacing all your spaces with
Here is an article that explains this a little more in-depth: http://webdesign.about.com/od/beginningtutorials/f/blfaqwhitespace.htm
To answer the question in the comment:
If you need to have a lot of control over exactly what is going out to your grid even when it is DataBound, you can simply handle the RowDataBound event that fires after each row is bound.
Suppose you have a GridView that looks like this:
In your code behind, you can handle the event to re-format the outgoing text however you please. For example:
That would effectively replace all spaces with
and preserve them even when rendered to the browser. Just remember your data will come back this way as well, so you will need to handle this on the server if you plan to pass this information back into persistent storage.