簡體   English   中英

添加GridView列標題的背景顏色

[英]Add background color of GridView column header

我正在使用OnRowDataBound方法設置某些單元格背景的顏色。

請參考以下代碼以獲取OnRowDataBound方法:

If e.Row.RowType = DataControlRowType.DataRow Then
    e.Row.Cells(0).CssClass = ""
End If

上面的代碼將更改表中第一行的背景顏色。 如何設置列標題的顏色? 由於我沒有在ASP.Net中使用BoundField ,所以無法設置HeaderStyle-CssClass

我指的是這個網站http://www.aspdotnet-suresh.com/2013/01/convert-gridview-columns-to-rows-in.html

為此,請使用DataControlRowType.Header

If (e.Row.RowType = DataControlRowType.Header) Then
    'set a class for the entire row
    e.Row.CssClass = "HeaderRow"

    'or define a color for the entire row
    e.Row.BackColor = Color.Red
End If

但您也可以在其他位置為標頭設置CSS類。

<asp:GridView ID="GridView1" runat="server" HeaderStyle-CssClass="HeaderRow">

要么

<asp:TemplateField HeaderStyle-CssClass="HeaderRow">

暫無
暫無

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

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