網上搜到的用CS方法,效果不好。
實現原理。
1、新建一個table,只顯示錶頭。(同理也可以新建一個GridView,添加一列空行,然後隱藏行,即可只顯示錶頭)
2、隱藏GridView的表頭(ShowHeader="false");
3、控制width實現對齊。
<table align="center" rules="all" style="width:100%; text-align: center; height: 70px; font-size: medium;" frame="border"> <tr > <td style="width:10%" align="center" rowspan="2">姓名<br></td> <td style="width:16%" colspan="2">星期一</td> <td style="width:16%" colspan="2">星期二</td> <td style="width:16%" colspan="2">星期三</td> <td style="width:16%" colspan="2">星期四</td> <td style="width:16%" colspan="2">星期五</td> </tr> <tr> <td style="width:8%">上午</td> <td style="width:8%">下午</td> <td style="width:8%">上午</td> <td style="width:8%">下午</td> <td style="width:8%">上午</td> <td style="width:8%">下午</td> <td style="width:8%">上午</td> <td style="width:8%">下午</td> <td style="width:8%">上午</td> <td style="width:8%">下午</td> </tr> </table> <div style="border-color: 1; border-style: groove; border-width: thin; OVERFLOW-Y:auto; OVERFLOW-X:hidden; HEIGHT:182px"> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" ShowHeader="False" Width="100%"> <Columns> <asp:BoundField DataField="MemberName" ItemStyle-Width="10%" HeaderText="MemberName" SortExpression="MemberName" /> <asp:BoundField DataField="MonM" HeaderText="MonM" ItemStyle-Width="8%" /> <asp:BoundField DataField="MonA" HeaderText="MonA" ItemStyle-Width="8%" /> <asp:BoundField DataField="TueM" HeaderText="TueM" ItemStyle-Width="8%" /> <asp:BoundField DataField="TueA" HeaderText="TueA" ItemStyle-Width="8%" /> <asp:BoundField DataField="WenM" HeaderText="WenM" ItemStyle-Width="8%" /> <asp:BoundField DataField="WenA" HeaderText="WenA" ItemStyle-Width="8%" /> <asp:BoundField DataField="ThurM" HeaderText="ThurM" ItemStyle-Width="8%" /> <asp:BoundField DataField="ThurA" HeaderText="ThurA" ItemStyle-Width="8%" /> <asp:BoundField DataField="FriM" HeaderText="FriM" ItemStyle-Width="8%" /> <asp:BoundField DataField="FriA" HeaderText="FriA" ItemStyle-Width="8%" /> </Columns> </asp:GridView> </div>
效果爲
美中不足的是,在ie上可以很好的對齊,但是在別的瀏覽器上有一點錯位。
不懂樣式,希望有人能給個好的樣式,使其更兼容。