簡體   English   中英

使用 CSS id 選擇器來設置 Gridview 控件的樣式

[英]Using CSS id selector to style Gridview control

我有一個現有的 CSS 文件,其中包含以下 2 個 id 選擇器:

#TableHead {
font-family: Arial, Helvetica, sans-serif;
font-size:11px;
font-weight: bold;
color: #000000;
border-top-width: thin;
border-top-style: solid;
border-top-color: #A9AAAA;
border-bottom-width: thin;
border-bottom-style: solid;
border-bottom-color: #A9AAAA;
}

#TableDivs {
border-bottom-width: 1px;
font-size:11px;
border-bottom-style: dotted;
font-family:Arial, Helvetica, sans-serif;
border-bottom-color: #A9AAAA;
}

I need to use "TableHead" to style Gridview header and "TableDivs" to style the rest of the Gridview control. 我可以通過在部分中包含 gridview 來使用 TableDivs。 如何使用 TableHead 設置 header 的樣式? 我應該在哪里指定 id="TableHead"?

Gridview 添加后的渲染源代碼為:

<div id="TableDivs">
  <div>
    <table cellspacing="0" rules="all" border="0" id="ctl00_Main_GridView1" style="border-width:0px;font-weight:normal;border-collapse:collapse;">
      <tr>
      <th align="left" scope="col">
          <a href="javascript:__doPostBack('ctl00$Main$GridView1','Sort$FileName')">File Name</a>
        </th>
        <th align="left" scope="col"><a href="javascript:__doPostBack('ctl00$Main$GridView1','Sort$Description')">Description</a>
        </th>
        <th align="left" scope="col"><a href="javascript:__doPostBack('ctl00$Main$GridView1','Sort$GroupName')">Folder Name</a>
        </th>
        <th align="left" scope="col">
          <a href="javascript:__doPostBack('ctl00$Main$GridView1','Sort$TimeAdded')">Date Added</a>
        </th>
    </tr>
      <tr>
      <td style="width:30%;">
          <a id="ctl00_Main_GridView1_ctl02_btnDownload" href="javascript:__doPostBack('ctl00$Main$GridView1$ctl02$btnDownload','')">2.txt</a>
        </td>
        <td style="width:40%;">222222</td><td style="width:25%;">group11</td>
        <td style="width:5%;">
          <span id="ctl00_Main_GridView1_ctl02_lblDateAdded"></span>
        </td>
    </tr>
      <tr>
      ...
    </tr>
    </table>
  </div>
</div>
<asp:GridView HeaderStyle-CssClass="your_class" ></asp:GridView>

理想情況下,您應該使用

Gridview .table, Gridview .th, Gridview .tr, Gridview .tr

選擇器。 這將幫助您 select、gridview 或所有類似的網格視圖,並為它們提供共同的外觀和感覺。

它還允許 CSS 進行樣式設置,而不是在 .NET 中編寫代碼並指定 class。

<asp:GridView ID="gridId" runat="server" >
    <HeaderStyle CssClass="TableHead" />
    <RowStyle CssClass="TableDivs" />
</asp:GridView>
<asp:GridView ID="TableDivs" runat="server" >
    use some js to get the parent of ths or just thead(if GridView can export thead), then add #TableHead to the element.
</asp:GridView>

感謝大家的幫助。 最后我別無選擇,只能修改所有 css 文件並添加新的 class 選擇器,因為我無法使用 id 選擇器。 我在 GridView 的 HeaderStyle、RowStyle、PagerStyle cssclass 屬性中使用了新的 class 選擇器。 現在工作正常。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM