Gridview宽度和对齐

时间:2016-03-23 08:32:30

标签: html css asp.net gridview

我有固定的标题表和gridview控件。我尝试了很多方法来修复每列下的每个列标题,但无法成功。当我在inspect中看到它时,它显示标题ID宽度为50px,这是正确的。但它显示了boundfield EmpID宽度66px,这是错误的。类似地,对于标题Employee显示150px是正确的但是对于显示200px的boundfield EmpName。如何修复宽度并使用标题和gridview结果对齐每个列?

<div style="height: 30px; margin: 0; padding: 0">
    <table id="tblHeader" class=""
        style="background-color: #336666; color: white; border-collapse: collapse; height: 100%;">
        <tr>
            <td style="text-align:left;width: 50px">
                <span>ID</span>
            </td>
            <td style="text-align:left;width: 150px">
                <span>Employee</span>
            </td>
        </tr>
    </table>
</div>

<div style="height: 360px; overflow: auto;">
    <asp:GridView ID="grdEmp" runat="server" AutoGenerateColumns="False"
        OnRowCommand="grdEmp_RowCommand" ShowHeader="false"
        GridLines="None" Font-Size="Small">
        <Columns>
            <asp:BoundField DataField="EmpID" ItemStyle-Width="50px">
            </asp:BoundField>
            <asp:BoundField DataField="EmpName">
                <ItemStyle CssClass="RowStyle150"></ItemStyle>
            </asp:BoundField>
        </Columns>
        <RowStyle BackColor="White" ForeColor="#333333" />
    </asp:GridView>
</div>

.RowStyle50 {
    text-align:left;
    padding-left: 0px;
    padding-right: 0px;
    width: 50px !important;
}

.RowStyle150 {
    text-align:left;
    padding-left: 0px;
    padding-right: 0px;
    width: 150px !important;
}

1 个答案:

答案 0 :(得分:1)

试试这个

LayoutManager