【问题标题】:Asp.net GridView ignore the CellSpacing attributeAsp.net GridView 忽略 CellSpacing 属性
【发布时间】:2009-10-06 17:48:51
【问题描述】:

我在这里的 GridView 遇到了一些困难,客户要求我在单元格之间放置一些空间,通常我会做 CellSpacing="5" 但它似乎不起作用,我尝试了一些东西,一切正常重写...

我试过的代码:

<asp:GridView ID="gvShoppingCart" runat="server" CellSpacing="5" Width="100%" AutoGenerateColumns="false">

<some-formating-columns-here />

</asp:GridView>

实际渲染的是:

<table cellpadding="0" cellspacing="0" summary="">
    <thead>
        <tr class="AspNet-GridView-Header">
            <th scope="col">Produit</th>
            <th scope="col"> </th>
            <th class="Center" scope="col">Quantité</th>
            <th class="Right" scope="col">  Prix Unitaire  </th>
            <th class="Right" scope="col">Prix</th>
        </tr>
    </thead>
<body-columns-here />
</table>

我现在不知道要添加什么...

有什么建议吗?

【问题讨论】:

  • 您能否确认您使用的是哪个版本的 ASP.NET 框架,以及您在哪个浏览器中看到了这种行为?另外,您是否定义了任何控制适配器? (您应该检查 /App_Browsers 文件夹中的 .browser 文件)。

标签: asp.net xhtml gridview


【解决方案1】:

我假设您使用的是 reset.css,因此您可能需要考虑执行以下操作;

在您的 css 文件中;

table {border-collapse:separate; border-spacing:5px} 

border-spacing 不是跨浏览器,因此您可能还需要在 GridView 上添加 CellSpacing="5"。

【讨论】:

    【解决方案2】:

    您是否尝试过使用 CSS。如果您知道应用于 HTML 元素的类,则可以对特定的 CSS 类使用 CSS-padding。我会试一试。

    一个例子是:

    <asp:GridView ID="gvShoppingCart" runat="server" CssClass="gvShoppingFormat" Width="100%" AutoGenerateColumns="false">
    <some-formating-columns-here />
    </asp:GridView>
    

    您的 CSS 类如下所示:

    .gvShoppingFormat td {
         padding-left: 5px;
         padding-right: 5px;
    }
    

    【讨论】:

    • 填充不是正确的选择,因为它会在单元格内部而不是外部添加空间。我想在每个单元格容器之间放置 5 个像素。我会是margin:5px,但似乎还不够。
    猜你喜欢
    • 2023-03-19
    • 1970-01-01
    • 2011-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-11
    • 1970-01-01
    相关资源
    最近更新 更多