如何获得一个圆角矩形图形跨越ASP.NET GridView标题行中的所有列?

时间:2009-07-10 12:13:00

标签: asp.net css gridviewheader

如何使圆角矩形图形跨越ASP.NET GridView标题行中的所有列?

我目前创建了一个圆角矩形图形,并使用CSS将其添加到gridview标题背景中: -

.datagrid th
{
    background-image: url('../images/rounded_graphic.jpg');
}

...但这只是在标题的每一列中显示它而不是跨越整个标题行。

有什么想法吗?

3 个答案:

答案 0 :(得分:1)

生成的数据网格必须在列之间没有间距。

  • 第一列需要圆角图像的左侧
  • 中间的列需要图像的中间部分
  • 最后一列会有图像的右侧

至少是粗略的想法:)

答案 1 :(得分:0)

使用带有headertemplate的templatefield

<asp:GridView ID="gvPrograms" runat="server"
        ...    
        >
        ...
        <Columns>
            <asp:TemplateField>
                <HeaderTemplate>
                     your header formatted as you like here...
                    <table>
                    </table>
                </HeaderTemplate>
                <ItemTemplate>
                </ItemTemplate>
                    your existing layout here...
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>            
</asp:GridView>

答案 2 :(得分:0)

我以前做过这个。这大致是我提出的代码:

<强> CSS

table th.first-column {
    background: url(images/layout/tb_left.png) 0 0 no-repeat;
}

table th {
    height: 26px;
    background: url(images/layout/tb_bg.png) 0 0 repeat-x;
}

/* Had some issues across browsers just putting the image in the <th>, had to use a span */
table th.last-column span {
    display: block;
    height: 26px;
    background: url(images/layout/tb_right.png) 100% 0 no-repeat;
}

<强> HTML

<table width="100%" cellspacing="0" cellpadding="0">
    <thead>
        <tr>
            <th class="first-column"><span>Column 1</span></th>
            <th><span>Column 2</span></th>
            <th><span>Column 3</span></th>
            <th class="last-column"><span>Column 4</span></th>
        </tr>
    </thead>
    <tbody>
        <tr>
        ...
        </tr>                           
    </tbody>
    <tfoot>
        <tr>
        ...
        </tr>
    </tfoot>
</table>

然后只需相应地创建你的图像,一切都应该没问题。我的第一个和最后一个列图像是几百个像素宽,在第一个的左边是圆形边缘,在最后一个右边是圆形边缘。中间背景图像仅为1x26像素,沿x轴重复。

相关问题