【问题标题】:Add background color of GridView column header添加 GridView 列标题的背景颜色
【发布时间】:2016-11-17 07:23:26
【问题描述】:

我正在使用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

【问题讨论】:

    标签: asp.net vb.net gridview


    【解决方案1】:

    您为此使用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">
    

    【讨论】:

    • 完全按照我想要的方式工作。谢谢。
    • 另一个是,如何使标题文本居中?我尝试添加e.Row.HorizontalAlign = HorizontalAlign.Center,但它不起作用。
    猜你喜欢
    • 2017-05-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-02
    • 2014-06-17
    • 2015-09-28
    • 2013-07-02
    • 1970-01-01
    相关资源
    最近更新 更多