Gridview sorted header css not loading
<p>I have a GridView that has it's columns loaded from codebehind.  The header CSS class I specified in the aspx page, but it wasn't loading for these columns.  So I added: GridView1.HeaderRow.CssClass = "HeaderStyle" in the codebehind after binding and then it loaded.  I can't figure out how to do this for the sorted column style though.</p>

<p>Here's the codebehind.  Any idea what I need to enter to style the sorted column and where it should be added? Can I specify "SortedAscendingHeaderStyle" and "SortedDescendingHeaderStyle" for the sorted column anywhere?</p>

<pre><code>Sub Page_load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    If Not Page.IsPostBack Then
        CreateGridColumns()
        BindGrid()
    End If
End Sub

Public Property SortExpression As String
    Get
        If ViewState("SortExpression") Is Nothing Then
            ViewState("SortExpression") = "LastName ASC"
        End If
        Return ViewState("SortExpression").ToString
    End Get
    Set(ByVal value As String)
        ViewState("SortExpression") = value
    End Set
End Property

Private Sub CreateGridColumns()
    Dim curLastName As New BoundField
    curLastName.HeaderText = "Last Name"
    curLastName.DataField = "LastName"
    curLastName.SortExpression = "LastName"

    GridView1.Columns.Insert(0, curLastName)


    Dim curFirstName As New BoundField
    curFirstName.HeaderText = "First Name"
    curFirstName.DataField = "FirstName"
    curFirstName.SortExpression = "FirstName"

    GridView1.Columns.Insert(1, curFirstName)

End Sub

Private Sub BindGrid()
    Try
        Dim tblData = New DataTable
        Using sqlCon As New SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("dbConnectionString").ConnectionString.ToString())
            Dim sql As String = "SELECT * FROM EmployeeList ORDER BY {0}"
            Dim sqlCmd = New SqlClient.SqlCommand()
            sqlCmd.CommandText = String.Format(sql, Me.SortExpression)
            sqlCmd.Connection = sqlCon
            Using objAdapter As New SqlClient.SqlDataAdapter(sqlCmd)
                objAdapter.Fill(tblData)
            End Using
        End Using
        GridView1.DataSource = tblData
        GridView1.DataBind()

        GridView1.HeaderRow.CssClass = "HeaderStyle"

    Catch ex As Exception
        ' TODO: log error '
        Throw
    End Try
End Sub
Private Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging
    Me.GridView1.PageIndex = e.NewPageIndex
    BindGrid()
End Sub

Private Sub GridView1_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles GridView1.Sorting
    Dim currentSortColumn, currentSortDirection As String
    currentSortColumn = Me.SortExpression.Split(" "c)(0)
    currentSortDirection = Me.SortExpression.Split(" "c)(1)
    If e.SortExpression.Equals(currentSortColumn) Then
        ' switch sort direction '
        Select Case currentSortDirection.ToUpper
            Case "ASC"
                Me.SortExpression = currentSortColumn &amp; " DESC"
            Case "DESC"
                Me.SortExpression = currentSortColumn &amp; " ASC"
        End Select
    Else
        Me.SortExpression = e.SortExpression &amp; " ASC"
    End If
    BindGrid()

End Sub
</code></pre>

<p>Here's the GridView mark up:</p>

<pre><code>&lt;asp:GridView  ID="GridView1"  runat="server"  AllowSorting="True"  AutoGenerateColumns="False" 
 EmptyDataText="There are no data records to display." AllowPaging="True" 
 CssClass="GridViewStyle" GridLines="None" Width="100%"&gt;

 &lt;Columns&gt;

    &lt;asp:BoundField DataField="Dept" HeaderText="Dept" SortExpression="Dept" /&gt;
    &lt;asp:HyperLinkField DataNavigateUrlFields="EmplID"
        DataNavigateUrlFormatString="EmployeeProfile.aspx?EmplID={0}"
        DataTextField="EmplID"
        DataTextFormatString= "&lt;img src='Images/icons/document-search-result.png' alt='View'/&gt; &lt;u&gt;View&lt;/u&gt;" &gt;
        &lt;ControlStyle CssClass="titleLinksB" /&gt;
    &lt;ItemStyle Wrap="False" /&gt;
    &lt;/asp:HyperLinkField&gt;

    &lt;/Columns&gt;
    &lt;RowStyle CssClass="RowStyle" /&gt;
        &lt;EmptyDataRowStyle CssClass="EmptyRowStyle" /&gt;
        &lt;PagerSettings Mode="NumericFirstLast" PageButtonCount="5" /&gt;
        &lt;PagerStyle CssClass="PagerStyle" /&gt;
        &lt;SelectedRowStyle CssClass="SelectedRowStyle" /&gt;
        &lt;HeaderStyle CssClass="HeaderStyle" /&gt;
        &lt;EditRowStyle CssClass="EditRowStyle" /&gt;
        &lt;AlternatingRowStyle CssClass="AltRowStyle" /&gt;
        &lt;SortedAscendingHeaderStyle CssClass="sortasc"&gt;&lt;/SortedAscendingHeaderStyle&gt;
        &lt;SortedDescendingHeaderStyle CssClass="sortdesc"&gt;&lt;/SortedDescendingHeaderStyle&gt;

&lt;/asp:GridView&gt;
</code></pre>

<p>Thank you for any help!</p>
