我在我的ASP.NET应用程序中使用Twitter Bootstrap时遇到问题。当我将table table-striped css类用于asp:GridView控件时,会将表的表头视为Row

我的GridView

ASP.NET标记

<asp:GridView ID="dgvUsers" runat="server"
    CssClass="table table-hover table-striped" GridLines="None"
    AutoGenerateColumns="False">
    <Columns>
        <asp:BoundField DataField="UserID" HeaderText="ID" Visible="false" />
        <asp:BoundField DataField="Username" HeaderText="Username" />
        <asp:BoundField DataField="FirstName" HeaderText="First Name" />
        <asp:BoundField DataField="LastName" HeaderText="Last Name" />
    </Columns>
    <RowStyle CssClass="cursor-pointer" />
</asp:GridView>

结果
<table id="cphMainContent_dgvUsers" class="table table-hover table-striped"
       cellspacing="0" style="border-collapse:collapse;">
    <tbody>
        <tr>
            <th scope="col">Username</th>
            <th scope="col">First Name</th>
            <th scope="col">Last Name</th>
        </tr>
        <tr class="cursor-pointer">
            <td>user1</td>
            <td>Test</td>
            <td>User 1</td>
        </tr>
        <tr class="cursor-pointer">
            <td>user2</td>
            <td>Test</td>
            <td>User 2</td>
        </tr>
        <tr class="cursor-pointer">
            <td>user3</td>
            <td>Test</td>
            <td>User 3</td>
        </tr>
    </tbody>
</table>

应该是这样
<table class="table table-striped">
    <thead>
        <tr>
            <th>#</th>
            <th>First Name</th>
            <th>Last Name</th>
            <th>Username</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>1</td>
            <td>Mark</td>
            <td>Otto</td>
            <td>@mdo</td>
        </tr>
        <tr>
            <td>2</td>
            <td>Jacob</td>
            <td>Thornton</td>
            <td>@fat</td>
        </tr>
        <tr>
            <td>3</td>
            <td>Larry</td>
            <td>the Bird</td>
            <td>@twitter</td>
        </tr>
    </tbody>
</table>

我怎样才能使Twitter Bootstrap将asp:GridView的 header 视为 header ?
我的代码是在VS2010 Pro中构建的C#,框架4中。

最佳答案

您需要将gridview的useaccessibleheader属性设置为true,然后在GridView对象上调用TableSection方法之后,还需要指定DataBind()作为 header 。因此,如果您的网格 View 是mygv

mygv.UseAccessibleHeader = True
mygv.HeaderRow.TableSection = TableRowSection.TableHeader

这将导致带有theadtbody标签的格式正确的网格

关于c# - Twitter Bootstrap和ASP.NET GridView,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12362361/

10-17 00:50