Eaten Taik Eaten Taik - 1 year ago 81 Question

Add background color of GridView column header

I am using

method to set the color of some cells background.

Refer below code for
method :

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

Above code will change the background color of 1st row in the table. How do I set the color of Column header? Since I am not using
in ASP.Net so I can't set the

I am referring to this site

Answer Source

You use the DataControlRowType.Header for that.

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

But you can also set the CSS class for the header in other places.

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


<asp:TemplateField HeaderStyle-CssClass="HeaderRow">
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download