Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>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.</p> <p>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.</p> <p>Try replacing all your spaces with <code>&amp;nbsp;</code></p> <p>Here is an article that explains this a little more in-depth: <a href="http://webdesign.about.com/od/beginningtutorials/f/blfaqwhitespace.htm" rel="nofollow noreferrer">http://webdesign.about.com/od/beginningtutorials/f/blfaqwhitespace.htm</a></p> <p><strong>To answer the question in the comment:</strong></p> <p>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 <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowdatabound.aspx" rel="nofollow noreferrer">RowDataBound</a> event that fires after each row is bound.</p> <p>Suppose you have a GridView that looks like this:</p> <pre><code>&lt;asp:GridView ID="gbGridWithSpaces" AutoGenerateColumns="false" runat="server" onrowdatabound="gbGridWithSpaces_RowDataBound"&gt; &lt;Columns&gt; &lt;asp:BoundField DataField="ItemWithSpaces" HeaderText="Item With Spaces" /&gt; &lt;/Columns&gt; &lt;/asp:GridView&gt; </code></pre> <p>In your code behind, you can handle the event to re-format the outgoing text however you please. For example:</p> <pre><code>protected void gbGridWithSpaces_RowDataBound(object sender, GridViewRowEventArgs e) { foreach (TableCell cell in e.Row.Cells) { cell.Text = cell.Text.Replace(" ", "&amp;nbsp;"); } } </code></pre> <p>That would effectively replace all spaces with <code>&amp;nbsp;</code> 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.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload