gridview產生時如何去掉style屬性中的border-collapse,gridview去掉邊框
在vs2005下用到gridview時,預設的情況下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><tr><td>2</td><td>2</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><tr><td>2</td><td>2</td></tr></table>
補充一點:
GridLines="None" 不顯示儲存格邊框
CellSpacing="-1" 去掉GridView style中的border-collapse:collapse;樣式
備忘:在firefox瀏覽器遇到的問題,邊框合并導致部分邊框線條變粗,GridLines="None" 可以解決
怎去除GridVIew的邊框 從分析用戶端入手
今天就將一個例子,是用GridView產生廢碼的清除。這次我們從用戶端產生的html分析一下。
具體的問題是GridView出現邊框,當然在不同的瀏覽器中顯示可能不太一樣,就是我們想去掉GridView的邊框,我們先不去著急修改GridView中的屬性,我們先看一看用戶端產生的html代碼,這是GridView產生的table
<table cellspacing="0" rules ="all" border="0" id="ctl00_ContentPlaceHolder1_GvLatestNews" style="border-style:None;border-collapse:collapse;"</table我們重點分析的是rules ="all" 這個屬性 這是協助文檔中的內容下面翻譯並解釋一下
Sets or retrieves which dividing lines (inner borders) are displayed. //rules是用來設定並檢索哪一個分隔線(內邊框)的顯示
Syntax //文法
HTML <TABLE RULES = sRule... //html中的文法為左邊形式
Scripting TABLE.rules [ = sRule ]//指令碼中的文法為左邊形式
Possible Values//可能的屬性值sRuleString that specifies or receives one of the following values.//sRule為字元型,用來指定或者接受一下幾種值
allBorders are displayed on all rows and columns. //all這個值,表示所有的行與列的邊框都會顯示
colsBorders are displayed between all table columns. //cols 表示只顯示table中列的邊框
groupsHorizontal borders are displayed between all tHead, tBody, and tFoot objects; //水平方向上的邊框顯示在所有的thead,tbody和tFoot對象之間
vertical borders are displayed between all colGroup objects. //垂直方向上的邊框顯示在所有的colGroup對象之間
noneAll interior table borders are removed. //移除全部的table內標籤
rowsHorizontal borders are displayed between all table rows. //水平方向上的邊框顯示在素有的table列之間
在html的css屬性中border-collapse:collapse;是什?
把表格邊框顯示為一條單獨的邊框,還是像標準的 HTML 中那樣分開顯示。
參考資料:www.w3school.com.cn/css/pr_tab_border-collapse.asp