在 VS2005 下使用 GridView 時,預設情況下控制項會在產生的 HTML style 屬性中加入 border-collapse:collapse;。
<asp:GridView ID="GridView1" runat="server" BorderWidth="0"></asp:GridView>
綁定資料執行後,頁面中的程式碼會變成:
<table cellspacing="0" rules="all" border="0" id="GridView1" style="border-width:0px;border-collapse:collapse;"> <tr> <th scope="col">id</th><th scope="col">name</th> </tr> <tr> <td>1</td><td>1</td> </tr> </table>
GridView 自動加上了 border-collapse:collapse;。若想去掉這段自動加入的程式碼,只要設定 CellSpacing="-1" 即可,加上後 HTML 變成:
<table rules="all" border="0" id="GridView1" style="border-width:0px;"> <tr> <th scope="col">id</th><th scope="col">name</th> </tr> <tr> <td>1</td><td>1</td> </tr> </table>
GridLines="None":不顯示儲存格邊框。
CellSpacing="-1":移除 GridView style 中的 border-collapse:collapse; 樣式。
備註:這是曾在 Firefox 遇到的問題——邊框合併導致部分邊框線條變粗,用 GridLines="None" 即可解決。