ASP.Net绑定到的GridView试纸一些空间(空白字符) [英] ASP.Net Binding to Gridview Strips some space (whitespace characters)

查看:357
本文介绍了ASP.Net绑定到的GridView试纸一些空间(空白字符)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从一个Oracle数据库中检索数据,并结合同一个GridView控件。

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:

要被淘汰尽快'

当检索到,它成为...

When retrieved, it becomes...

要被淘汰尽快'

和另一个...

这是我们测试记录DDDFFF

IT''S TEST RECORD" DDD " FFF

变成

这是我们测试记录DDDFFF

IT''S TEST RECORD" DDD " FFF

我没有任何线索,为什么发生这种情况...

I don't have any clue why this is happening...

什么想法?

我想即使这里的空间越来越修剪。在我的第一个字段的例子是:

I think even here the spaces are getting trimmed. In my example in the first field which is:

要被淘汰尽快'。

其实有单引号后的两个空格,但在这里只显示一个空格..奇...

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 --> ' "

我觉得一个引号或单引号后的额外空间正在被拆除asp.net ??

I think the extra space after a quote or single quote is being removed by asp.net??

我还发现,当我编辑我的GridView,多余的空格被保留,但是当我回到原来的观点,空格都没有了。

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.

要改一下这个问题。

显示数据时,我如何preserve空白在GridView?

How Do I Preserve the WhiteSpace in the gridview when displaying the data?

推荐答案

这是不是一个ASP.Net的东西,它是一个HTML解析的事情。如果你要创建一个纯简的HTML页面中有一个div标签,然后把打开和关闭标签,将所有被压缩成一个空间的100个停车位。

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.

这是一个典型的网络问题。如果你真的想拥有的一切正确出来,那么你就需要HTML EN code任何空格在页面上展示他们面前。

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.

试着用替换所有的空格&放大器; NBSP;

Try replacing all your spaces with  

下面是解释这多一点深入的文章: HTTP: //webdesign.about.com/od/beginningtutorials/f/blfaqwhitespace.htm

Here is an article that explains this a little more in-depth: http://webdesign.about.com/od/beginningtutorials/f/blfaqwhitespace.htm

要回答在评论的问题:

如果你需要有很多的控制权到底是怎么回事到您的网格即使是数据绑定,你可以简单地处理的的RowDataBound 事件每一行后大火被绑定。

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.

假设你有一个GridView,看起来像这样:

Suppose you have a GridView that looks like this:

<asp:GridView ID="gbGridWithSpaces" AutoGenerateColumns="false" runat="server" 
    onrowdatabound="gbGridWithSpaces_RowDataBound">
    <Columns>
        <asp:BoundField DataField="ItemWithSpaces" HeaderText="Item With Spaces" />
    </Columns>
</asp:GridView>

在您的code的背后,你能处理该事件然而,重新格式化文本传出请你。例如:

In your code behind, you can handle the event to re-format the outgoing text however you please. For example:

protected void gbGridWithSpaces_RowDataBound(object sender, GridViewRowEventArgs e)
{
    foreach (TableCell cell in e.Row.Cells)
    {
        cell.Text = cell.Text.Replace(" ", "&nbsp;");
    }
}

这将有效地取代&放所有的空格; NBSP;即使呈现给浏览器和preserve他们。请记住您的数据将通过这种方式回来一样,所以你需要处理这个服务器上,如果你打算回来将此信息传递到永久存储。

That would effectively replace all spaces with &nbsp; 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.

这篇关于ASP.Net绑定到的GridView试纸一些空间(空白字符)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆