如何在VB.NET中向GridView表添加标题行?

时间:2014-04-09 21:11:08

标签: html vb.net

<asp:GridView ID="MemberTable" runat="server" 
    AutoGenerateColumns="False" 
    CellPadding="4" DataKeyNames="ID" DataSourceID="AccessDataSource1" 
    EmptyDataText="There are no data records to display." ForeColor="#333333" 
    GridLines="None" HorizontalAlign="Center">
    <AlternatingRowStyle BackColor="White" />
    <Columns>
        <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
        <asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="True" SortExpression="ID" />
        <asp:BoundField DataField="Forename" HeaderText="Forename" SortExpression="Forename" />
        <asp:BoundField DataField="Surname" HeaderText="Surname" SortExpression="Surname" />
        <asp:BoundField DataField="DOB" HeaderText="DOB" SortExpression="DOB" />
        <asp:BoundField DataField="EmailAddress" HeaderText="EmailAddress" SortExpression="EmailAddress" />
        <asp:BoundField DataField="Username" HeaderText="Username" SortExpression="Username" />
        <asp:BoundField DataField="Password" HeaderText="Password" SortExpression="Password" />
        <asp:BoundField DataField="UserType" HeaderText="UserType" SortExpression="UserType" />
    </Columns>
    <EditRowStyle BackColor="#7C6F57" />
    <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
    <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
    <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
    <RowStyle BackColor="#E3EAEB" />
    <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
    <SortedAscendingCellStyle BackColor="#F8FAFA" />
    <SortedAscendingHeaderStyle BackColor="#246B61" />
    <SortedDescendingCellStyle BackColor="#D4DFE1" />
    <SortedDescendingHeaderStyle BackColor="#15524A" />
</asp:GridView>

Table

如何在此表的最顶部添加单个单元格标题行? (最好只使用标签)

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

GridViews无法控制桌面页眉,页脚或单元格。

但是,你说你想要一个&#34;单个单元格标题行&#34;,这听起来像你正在寻找一个标题。这是可能的;请参阅MSDN GridView.Caption

<asp:GridView (...) Caption="Hello Table!" CaptionAlign="Left">

通过一些css样式,你可以使标题看起来就像一个表格行。

<style type="text/css">
  caption {background-color:#E3EAEB; padding:4px}
</style>

enter image description here