添加GridView列标题的背景颜色

时间:2016-11-17 07:23:26

标签: asp.net vb.net gridview

我使用OnRowDataBound方法设置某些单元格背景的颜色。

请参阅以下OnRowDataBound方法的代码:

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

以上代码将更改表格中第1行的背景颜色。如何设置Column标题的颜色?由于我没有在ASP.Net中使用BoundField,因此我无法设置HeaderStyle-CssClass

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

1 个答案:

答案 0 :(得分:0)

您可以使用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">
相关问题